|
-
December 19th, 2010, 07:22 PM
#1
noob help needed
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.
ok this is what i had to do, and this is the code i wrote so far, what am i doing wrong?? please help
/**
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()
{
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;
}
}
and the tester..
public class ProductPrinter
{
public static void main(String[] args)
{
Product p = new Product();
p.name("toaster");
p.price(29.95);
System.out.println(price);
}
}
idk what im doing wrong really, im so lost
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|