Cash Register

Another very tough week on the programming front. With the assistance of the ever patient and helpful graduate assistant, P$(@$(&k, I managed to cobble together some workable code. Below is the driver for the assignment (Coin and CashRegister classes used, not displayed here…why further embarass myself?):

public class CashRegisterDriver
{
public static void main(String[] args)
{
//Create coin set by integer value and type name
Coin penny = new Coin(1, “penny”);
Coin nickel = new Coin(5, “nickel”);
Coin dime = new Coin(10, “dime”);
Coin quarter = new Coin(25, “quarter”);

Scanner in = new Scanner(System.in);

CashRegister register = new CashRegister();

//Input a purchase price amount for class CashRegister
//Input via Scanner
System.out.print(“Enter price: “);
int price = in.nextInt();
register.recordPurchase(price);

//Input payment amount for class CashRegister
//Create variable names for each coin type for payment method
System.out.print(“Please enter your payment as requested: \n”);
System.out.print(“Enter # of quarters: “);
int quarters = in.nextInt();
register.enterPayment(quarters, quarter);
System.out.print(“Enter # of dimes: “);
int dimes = in.nextInt();
register.enterPayment(dimes, dime);
System.out.print(“Enter # of nickels: “);
int nickels = in.nextInt();
register.enterPayment(nickels, nickel);
System.out.print(“Enter # of pennies: “);
int pennies = in.nextInt();
register.enterPayment(pennies, penny);

//Alert user to transaction values
System.out.print(“The price is: ” + register.purchase + “\n”);
System.out.print(“You have paid a total of: ” + register.payment + “\n”);
System.out.print(“Your change due is: ” + (register.payment – register.purchase) + “\n”);

//Create variable name for change method for each coin type created above
int q = register.giveChange(quarter);
register.giveChange(quarter);
System.out.print(“Quarters returned: ” + q + “\n”);
int d = register.giveChange(dime);
register.giveChange(dime);
System.out.print(“Dimes returned: ” + d + “\n”);
int n = register.giveChange(nickel);
register.giveChange(nickel);
System.out.print(“Nickels returned: ” + n + “\n”);
int p = register.giveChange(penny);
register.giveChange(penny);
System.out.print(“Pennies returned: ” + p + “\n”);

}
}

Any programmer that reads this will note that all monies and transactions are integer type…..I can’t figure out how to express an integer value in double format, nor can I figure out how to cast a double to an integer. If you are in my class, please don’t get us both in trouble by copying/using this doggerel.

Advertisements

0 Responses to “Cash Register”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




“Life’s hard, son. It’s harder when you’re stupid.” — The Duke.

Education is a companion which no misfortune can depress, no crime can destroy, no enemy can alienate,no despotism can enslave. At home, a friend, abroad, an introduction, in solitude a solace and in society an ornament.It chastens vice, it guides virtue, it gives at once grace and government to genius. Without it, what is man? A splendid slave, a reasoning savage. - Joseph Addison
The term informavore (also spelled informivore) characterizes an organism that consumes information. It is meant to be a description of human behavior in modern information society, in comparison to omnivore, as a description of humans consuming food. George A. Miller [1] coined the term in 1983 as an analogy to how organisms survive by consuming negative entropy (as suggested by Erwin Schrödinger [2]). Miller states, "Just as the body survives by ingesting negative entropy, so the mind survives by ingesting information. In a very general sense, all higher organisms are informavores." - Wikipedia

Blog Stats

  • 30,477 hits

%d bloggers like this: