I am having a problem with getting this to work.
does anyone have any ideas?
here is the code:
and the output:Code:import java.io.*; import java.math.*; import java.util.*; public class CashRegisterTester { public static void main(String[] args) { CashRegister register = new CashRegister(); register.recordPurchase(0.75); register.recordPurchase(1.50); register.enterPayment(2,0,5,0,0); System.out.print("Change= "); System.out.println(register.giveChange()); } public class CashRegister { public CashRegister() { 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; } }
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context
at CashRegisterTester.main(CashRegisterTester.java:13)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
Any help would be greatly appreciated.




Reply With Quote