Results 1 to 8 of 8
  1. #1
    vampire-elf is offline Member
    Join Date
    Sep 2010
    Location
    Zeist, Holland
    Posts
    4
    Rep Power
    0

    Default class that wont work out properly.

    Hello,

    I just started learning java and was wondering if someone could help me out.

    the main:
    public class Main

    {
    public static void main(String [] arg)
    {

    Product pr1 = new Product("Ipad", "1234AB", 614.00);
    pr1.setBTW(19.0);
    pr1.verhoogPrijsMet(2.5);
    System.out.println("Eerste product: " + pr1.pr1());
    System.out.println();

    Product pr2 = new Product("Paracetamol", "5678CD");
    pr2.setPrijs(1.90);
    pr2.verhoogPrijsMet(-10);
    pr2.setBTW(6.0);
    System.out.println("Tweede product " + pr2.pr2());
    System.out.println("BTW percentage " + pr2.getBTW());
    System.out.println("betaalde BTW " + pr2.btwBedrag());
    System.out.println("Prijs: " + pr2.getPrijs());
    }
    }

    the main is not allowed to be changed in any way.

    the class:
    public class Product {

    private String naam;
    private String code;
    private double btw;
    private double prijs;

    public Product(String nm, String cd) {

    naam = nm;
    code = cd;
    }

    public Product(double pr, double B)

    {
    prijs = pr;
    btw = B;

    }

    public String getNaam()

    {
    return naam;
    }


    public String getCode()
    {
    return code;

    }

    public double getPrijs()
    {
    return prijs;
    }

    public double getBTW()
    {
    return btw;
    }

    public void setBTW(double nB)
    {
    btw = nB;
    }

    public void setPrijs(double pr)

    {
    prijs = pr;
    }


    public double btwBedrag()

    {
    double btw = prijs - 1.9 / 1.9 * 100;
    return btw;
    }
    public Double pr1(double naam)
    {
    return naam;
    }


    public String pr1( )

    {
    String pr1 = naam + "heeft code " + code + "en kost " + prijs
    + "; de btw is " + btw + "%";
    return pr1;
    }

    public String pr2()
    {
    String h = naam + "heeft code " + code + " en kost " + prijs +
    "; de btw is " + btw + "%";

    return h;
    }

    }

    The outcome should be:
    Eerste product: Ipad heeft code 1234AB en kost 629.35; de btw is 19.0%

    Tweede product: Peracetamol heeft code 5678CD en kost 1.71; de btw is 6.0%
    btw percentage: 6.0
    betaalde btw: 0.1026
    prijs:1.71

    However I get a error: cannot find symbol.
    Product pr1 = new Product("Ipad", "1234AB", 614.00);

    I do not know how to solve that, seeing as its a double in a string.
    And I don't know how to use verhoogPrijsMet which should raise Prijs by 2.5% and in pr2 should lower prijs by 10%, but I'm inable to do so somehow.

    All I get as an outcome is:
    Eerste product: Ipad heeft code1234ABen kost 0.0; de btw is19.0%

    Tweede product: Peracetamolheeft code 5678CDen kost 1.9; de btw is6.0%
    btw percentage: 6.0
    betaalde btw: 98.1
    prijs:1.9

    As you see it's not even close to what it should be.
    So if anyone can help me with this I would be extremely grateful.

    Greets,

    Vampire-elf

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Two comments about your posting:
    1) Use code tags surrounding your code to preserve its formatting.
    2) Copy and paste here the FULL text of all error messages. They contain necessary info to solve your problems.

    I get a error: cannot find symbol.
    If you get compiler errors, how are you able to execute the program?

  3. #3
    vampire-elf is offline Member
    Join Date
    Sep 2010
    Location
    Zeist, Holland
    Posts
    4
    Rep Power
    0

    Default

    I don't know how i just pushed the wrong button and it popped up.
    I know it was after i took out verhoogPriijsMet to see what would change.


    > Executing: C:\Program Files (x86)\ConTEXT\ConExec.exe "C:\Program Files (x86)\bin\javac.exe" "D:\java\Main.java"

    D:\java\Main.java:9: cannot find symbol
    symbol : constructor Product(java.lang.String,java.lang.String,double)
    location: class Product
    Product pr1 = new Product("Ipad", "1234AB", 614.00);
    ^

    D:\java\Main.java:13: cannot find symbol
    symbol : method verhoogPrijsMet(double)
    location: class Product
    pr1.verhoogPrijsMet(2.5);
    ^

    D:\java\Main.java:23: cannot find symbol
    symbol : method verhoogPrijsMet(int)
    location: class Product
    pr2.verhoogPrijsMet(-10);
    ^

    3 errors
    > Execute finished.

    Thats all i get at the moment but I'm guessing there is more.
    And sorry for posting the code wrong. I did not see that until i posted.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    You have the wrong args for the Constructor call. Look at the definition for the class.
    And its probably the same problem with the method call. Look at its definition.

    Make sure the args match number and type with the requirements shown in the definition.

  5. #5
    vampire-elf is offline Member
    Join Date
    Sep 2010
    Location
    Zeist, Holland
    Posts
    4
    Rep Power
    0

    Default

    I'm sorry I do not know what you mean as I learn Java in Dutch.

    Do you mind showing me or something so I know what you mean?
    Or maybe explain it step by step.

    Sorry for the trouble :(

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    constructor Product(java.lang.String,java.lang.String,double)

    Is there a Product class constructor with those arguments?


    Where is the method: verhoogPrijsMet defined?

    I learn Java in Dutch
    I don't speak Dutch so that will be a problem.

  7. #7
    vampire-elf is offline Member
    Join Date
    Sep 2010
    Location
    Zeist, Holland
    Posts
    4
    Rep Power
    0

    Default

    verhoogPrijMet isnt defined because every way I knew how to did not work out and basically atm I dont think I know how to define it so it actually works.

    So if I put the Prijs with public Product that defines naam and code, that part should work? (if I understood that correctly)

    Heh i know its a problem but my English is not THAT bad so I do understand alot I just haven't heard of those expessions in class. So i do not know what part of code you're takling about then :p

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    I just haven't heard of those expressions
    Do you know what a class's construtor is?
    Can you find the Product class's constructor?
    Does it have the arguments that you use in your code?

    Please copy and paste here both the Product class's constructor and your usage of it if you are not sure what I am talking about.

    I dont think I know how to define it
    At least code the signature of the method and leave the body empty until you figure out what to put there.

Similar Threads

  1. JApplet buttons wont work
    By Mark101 in forum New To Java
    Replies: 3
    Last Post: 03-16-2010, 06:53 PM
  2. Why wont import jm.util.*; work??
    By cakepizza in forum New To Java
    Replies: 2
    Last Post: 01-01-2010, 11:19 PM
  3. Replies: 3
    Last Post: 10-26-2009, 11:42 AM
  4. Why wont my object render properly
    By toecutter in forum AWT / Swing
    Replies: 3
    Last Post: 10-22-2009, 01:43 PM
  5. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 AM

Posting Permissions

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