Created
November 12, 2008 07:48
-
-
Save danahern/24106 to your computer and use it in GitHub Desktop.
A cash register to tell change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.developer.com/open/article.php/610011 | |
import javax.swing.JOptionPane; | |
class cashier | |
{ | |
private static final int penny_value = 1; | |
private static final int nickel_value = 5; | |
private static final int dime_value = 10; | |
private static final int quarter_value = 25; | |
private static final int dollar_value = 100; | |
String input; | |
double recieved; | |
double amountdue; | |
double tempchange; | |
int change = 0; | |
int pennies = 0; | |
int nickels = 0; | |
int dimes = 0; | |
int quarters = 0; | |
int dollars = 0; | |
public cashier() | |
{ | |
} | |
void setAmountDue() | |
{ | |
input = JOptionPane.showInputDialog("What is the Amount Due?"); | |
amountdue = Double.parseDouble(input); | |
} | |
void recieve() | |
{ | |
input = JOptionPane.showInputDialog("What is the Amount Recieved?"); | |
recieved = Double.parseDouble(input); | |
tempchange = (recieved-amountdue)*100; | |
change = (int)tempchange; | |
} | |
int returndollars() | |
{ | |
dollars = change / dollar_value; | |
change = change % dollar_value; | |
return dollars; | |
} | |
int returnquarters() | |
{ | |
quarters = change / quarter_value; | |
change = change % quarter_value; | |
return quarters; | |
} | |
int returndimes() | |
{ | |
dimes = change / dime_value; | |
change = change % dime_value; | |
return dimes; | |
} | |
int returnnickels() | |
{ | |
nickels = change / nickel_value; | |
change = change % nickel_value; | |
return nickels; | |
} | |
int returnpennies() | |
{ | |
pennies = change / penny_value; | |
change = change % penny_value; | |
return pennies; | |
} | |
} | |
/* | |
Double returndollars() | |
{ | |
change (int)(dollars*(recieved-amountdue)); | |
return change/dollars; | |
*/ | |
/*instance variables | |
private int pennies | |
nickels | |
dimes | |
quarters | |
dollars | |
change | |
private Double amountdue | |
recieved | |
public Double returndimes() | |
{ | |
change - change % quaters; | |
return change/dimes; | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class customer | |
{ | |
public static void main(String[] args) | |
{ | |
cashier harry = new cashier(); | |
harry.setAmountDue(); | |
harry.recieve(); | |
int dollars = harry.returndollars(); | |
int quarters = harry.returnquarters(); | |
int dimes = harry.returndimes() ; | |
int nickels = harry.returnnickels(); | |
int pennies = harry.returnpennies(); | |
System.out.println("The number of dollars returned is: " +dollars); | |
System.out.println("The number of quarters returned is: " +quarters); | |
System.out.println("The number of dimes returned is: " +dimes); | |
System.out.println("The number of nickels returned is: " +nickels); | |
System.out.println("The number of pennies returned is: " +pennies); | |
/* | |
cashier tester = new cashier(); | |
tester.setAmountDue(); | |
tester.recieve(); | |
dollars = tester.returndollars(); | |
quarters = tester.returnquarters(); | |
dimes = tester.returndimes(); | |
nickels = tester.returnnickels(); | |
pennies = tester.returnpennies(); | |
System.out.println("The number of dollars returned is: " +dollars); | |
System.out.println("The number of quarters returned is: " +quarters); | |
System.out.println("The number of dimes returned is: " +dimes); | |
System.out.println("The number of nickels returned is: " +nickels); | |
System.out.println("The number of pennies returned is: " +pennies); | |
*/ | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment