Results 1 to 7 of 7
  1. #1
    End Of All is offline End Of All
    Join Date
    Jul 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default error with CashRegister

    I have created this code and need help to fix it.

    Java Code:
    import java.io.*;
    import java.math.*;
    import java.util.*;
    
    public class CashRegister 
    {
        public static void main(String[] args) 
        {
            CashRegister register = new CashRegister();
            
            register.recordPurchase(20.37);
            register.enterDollars(20);
            register.enterQuarters(2);
            System.out.print("Change= ");
            System.out.println(register.giveChange());
        }
                
            {
                purchase = 0;
                payment = 0;
            }
            public void recordPurchase(double amount)
            {
                purchase = purchase + amount;
            }
            public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies)
            {
                payment = dollars + quarters * QUARTER_VALUE + dimes * DIME_VALUE 
                           + nickels * NICKEL_VALUE + pennies * PENNY_VALUE;
            }
            public double giveChange()
            {
                double change = payment - purchase;
                purchase = 0;
                payment = 0;
                return change;
            }
            
            public static final double QUARTER_VALUE = 0.25;
            public static final double DIME_VALUE = 0.1;
            public static final double NICKEL_VALUE = 0.05;
            public static final double PENNY_VALUE = 0.01;
            
            private double purchase;
            private double payment;    
    }
    here is the output:

    run:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: CashRegister.enterDollars
    at CashRegister.main(CashRegister.java:16)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    does anyone have any ideas?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: error with CashRegister

    register.enterDollars(20);
    register.enterQuarters(2);

    Where are these methods?

  3. #3
    End Of All is offline End Of All
    Join Date
    Jul 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: error with CashRegister

    it is a different way of doing this.

    register.enterPayment(20,0,2,0,0)

    I have altered the code to this

    Java Code:
    import java.io.*;
    import java.math.*;
    import java.util.*;
    
    public class CashRegister 
    {
        public static void main(String[] args) 
        {
            CashRegister register = new CashRegister();
            
            register.recordPurchase(20.37);
            register.enterdollars(20);
            register.enterquarters(2);
            System.out.print("Change= ");
            System.out.println(register.giveChange());
        }
                
            {
                purchase = 0;
                payment = 0;
            }
            public void recordPurchase(double amount)
            {
                purchase = purchase + amount;
            }
            public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies)
            {
                payment = dollars + quarters * QUARTER_VALUE + dimes * DIME_VALUE 
                           + nickels * NICKEL_VALUE + pennies * PENNY_VALUE;
            }
            public double giveChange()
            {
                double change = payment - purchase;
                purchase = 0;
                payment = 0;
                return change;
            }
            public void enterdollars(int dollars)
            {
                
            }
            public void enterquarters(int quarters)
            {
                
            }
            
            public static final double QUARTER_VALUE = 0.25;
            public static final double DIME_VALUE = 0.1;
            public static final double NICKEL_VALUE = 0.05;
            public static final double PENNY_VALUE = 0.01;
            
            private double purchase;
            private double payment;    
    }
    It gives me the output of:

    run:
    Change= -20.37
    BUILD SUCCESSFUL (total time: 0 seconds)

    which is nowhere near mathematically correct
    Last edited by End Of All; 07-23-2012 at 11:49 PM. Reason: missing info

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: error with CashRegister

    Quote Originally Posted by End Of All View Post
    which is nowhere near mathematically correct
    I don`t understand your problem, why is that not mathematically correct?

    recordPurchase 20.37 = -> purchase = purchase + amount; --> purchase = 0 + 20.37 --> purchase = 20.37
    giveChange = -> double change = payment - purchase; -> payment is 0 -> 0 - 20.37 = -20.37
    This is exactly the same as the output ?! What you'd expect as output?
    Have you forgotten to call the method enterpayment maybe?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: error with CashRegister

    Nothing NetBeans-specific. Moving to New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,521
    Blog Entries
    7
    Rep Power
    20

    Default Re: error with CashRegister

    Quote Originally Posted by End Of All View Post
    Change= -20.37
    BUILD SUCCESSFUL (total time: 0 seconds)

    which is nowhere near mathematically correct
    Yes it is because you didn't pay anything (those enterDollars( ... ) and enterQuarters( ... ) methods don't do anything).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    End Of All is offline End Of All
    Join Date
    Jul 2012
    Location
    USA
    Posts
    17
    Rep Power
    0

    Default Re: error with CashRegister

    Quote Originally Posted by eRaaaa View Post
    I don`t understand your problem, why is that not mathematically correct?

    recordPurchase 20.37 = -> purchase = purchase + amount; --> purchase = 0 + 20.37 --> purchase = 20.37
    giveChange = -> double change = payment - purchase; -> payment is 0 -> 0 - 20.37 = -20.37
    This is exactly the same as the output ?! What you'd expect as output?
    Have you forgotten to call the method enterpayment maybe?
    I originally used enterpayment and it seems to be rather aggravating that it doesn't work without it.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  2. Need help with CashRegister program
    By Aimforthehead in forum New To Java
    Replies: 4
    Last Post: 11-13-2011, 10:29 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 3
    Last Post: 01-23-2009, 08:53 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
  •