noob help needed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: noob help needed

  1. #1
    Join Date
    Dec 2010
    Posts
    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

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: noob help needed

    You need to tell us what your code is doing that it shouldn't or isn't doing what it should. If there are any compiler or runtime errors cut and paste them into your post.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center