Question

Write the program in java Implement a class Product. Create instance variables to store product name...

  1. Write the program in java
  2. Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.

Homework Answers

Answer #1
//Product.java
public class Product {
  private String name;
  private double price;

  public Product(String name, double price) {
    this.name = name;
    this.price = price;
  }

  public String getName() {
    return name;
  }

  public double getPrice() {
    return price;
  }

  public void productPrinter(){
    System.out.println(name+": "+(price-5));
  }

  public static void main(String[] args) {
    Product p = new Product("Toaster",29.95);
    p.productPrinter();
  }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have types str, int and float. Your class must have a constructor method to initialize the variables to an appropriate value, and methods for setting the value of each instance variable (set methods) and for retrieving the instance variable values (get methods). You can use the credit card code we looked at for assistance.
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class (5 points extra credit) Create another class called CourseSection (20 points extra credit) Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
JAVA Rational Numbers Create a Rational number class in the same style as the Complex number...
JAVA Rational Numbers Create a Rational number class in the same style as the Complex number class created in class. That is, implement the following methods: constructor add sub mul div toString You must also provide a Main class and main method to fully test your Rational number class.
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
Use Java To(with Explaination of Steps Please): You’re given a class Employee that represents a worker...
Use Java To(with Explaination of Steps Please): You’re given a class Employee that represents a worker in some unknown industry.Each employee has a name , balance and an hourly rate that is unique to them. So Worker1 can have a rate of $5 per hour and Worker2 can have $8 per hour. There are 2 constructors – one that lets you specify the name, a starting balance and the rate,and another that only lets you specify the name and rate...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Suppose that people's heights (in centimeters) are normally distributed, with a mean of 170 and a...
    asked 3 minutes ago
  • Use the information from the following Income Statement to create and Projected Income Statement and solve...
    asked 16 minutes ago
  • An unequal tangent vertical curve has the following elements: g1=-3.25%, g2=75%, total length = 500.00’, length...
    asked 18 minutes ago
  • Please write clear definitions of the following legal terms. Commerce Clause Supremacy Clause Indictment Tort
    asked 22 minutes ago
  • Do you think Moralistic Therapeutic Deism is an accurate reflection of society today? What are relevant...
    asked 27 minutes ago
  • The mean operating cost of a 737 airplane is $2,071 per day. Suppose you take a...
    asked 36 minutes ago
  • Arguments can be made on both sides of this debate about the ethical implications of using...
    asked 42 minutes ago
  • In the Chapter, they mention the idea of strategizing around your cash flows. Why are cash...
    asked 47 minutes ago
  • Company A signed a fixed-price $6,500,000 contract to construct a building. At the end of Year...
    asked 48 minutes ago
  • An unequal tangent vertical curve has the following elements: g1=-3.25%, g2=1.75%, total length = 500.00’, length...
    asked 54 minutes ago
  • In a previous​ year, 61​% of females aged 15 and older lived alone. A sociologist tests...
    asked 1 hour ago
  • Topic: Construction - Subsurface Investigation (Note: Briefly discuss in your own words, 1 paragraph minimum.) Typically...
    asked 1 hour ago