for home work assignment we have to
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.
/**
A product with a name and a price.
*/
public class Product
{
private String n;
private double p;
/**
Constructs a product with a given name and price.
@param n the name
@param p the price
*/
public Product(String n, double p)
{
n = "toaster";
p = 29.95;
}
/**
Gets the product name.
@return the name
*/
public String getName()
{
String name = "toaster";
return name;
}
/**
Gets the product price.
@return the price
*/
public double getPrice()
{
double price = 29.95;
return price;
}
/**
Reduces the product price.
@param amount the amount by which to reduce the price
*/
public void reducePrice(double amount)
{
double price = price - amount;
}
}
public class ProductPrinter
{
public static void main(String[] args)
{
Product p = new Product();
p.getName();
p.getPrice();
System.out.println(p);
}
}
and i get this
compile
fail
run
fail
Compiling Main Program
fail
Compiling 1 source file to /var/folders/N+/N+SKIiskEveKsGCwnqC83++++TI/-Tmp-/asnmt668102usr1966762-submit-1292801884349
/var/folders/N+/N+SKIiskEveKsGCwnqC83++++TI/-Tmp-/asnmt668102usr1966762-submit-1292801884349/ProductPrinter.java:5: cannot find symbol
symbol : constructor Product()
location: class Product
Product p = new Product();
^
1 error
/var/folders/N+/N+SKIiskEveKsGCwnqC83++++TI/-Tmp-/check8852985623170383351.xml:324: Compile failed; see the compiler error output for details.
Running Main Program
fail