Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NOTE: The completed code must pass in the following compiler. Please make absolu

ID: 3775697 • Letter: N

Question

NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4fp&problem=ch03/c03_exp_3_9


And PLEASE post this as text and not as an image.
~

Implement a class Product. A product has a name and a price, for example new Product("Toaster", 29.95). Supply methods getName, getPrice, and reducePrice. Supply a program ProductPrinter that makes two products, prints the name and price, reduces their prices by $5.00, and then prints the prices again.

Your main class should be called ProductPrinter.

Complete the following class in your solution:

Complete the following files:

Product.java

ProductPrinter.java

Explanation / Answer

/**
A product with a name and a price.
*/
class Product
{
private String name;

private double price;
/**
Constructs a product with a given name and price.
@param n the name
@param p the price
*/
public Product(String n, double p)
{
this.name=n;
this.price=p;
}

/**
Gets the product name.
@return the name
*/
public String getName()
{
return name;
}

/**
Gets the product price.
@return the price
*/
public double getPrice()
{
return price;
}

/**
Reduces the product price.
@param amount the amount by which to reduce the price
*/
public void reducePrice(double amount)
{
price=price-amount;
}
}

--------------------------------------------------output-------------------------------------------------------------

product1 name: Toaster
product1 price: 29.95
product2 name: Microwave
product2 price: 124.95
product1 price: 24.95
product2 price: 119.95