0

Hi all, i have been given an assignment asking me to: "The CashRegister class has an unfortunate limitation: It is closely tied to the coin system in the United States and Canada. Research the system used in most of Europe. Your goal is to produce a cash register that works with euros and cents. Rather than designing another limited CashRegister implementation for the European market, you should design a separate Coin class (for Euro coins system) and a new CashRegister class that can work with coins of all types."

I seem to be stuck and have tried for a couple days to figure it out (i'm new to java) and would appreciate some help!

Here's what i have so far:

public class CashRegister
{
/**
Constructs a cash register with no money in it.
*/
public CashRegister()
{
purchase = 0;
payment = 0;
}


/**
Records the purchase price of an item.
@param amount the price of the purchased item
*/
public void recordPurchase(double amount)
{
purchase = purchase + amount;
}


/**
Enters the payment received from the customer.
@param dollars the number of dollars in the payment
@param quarters the number of quarters in the payment
@param dimes the number of dimes in the payment
@param nickels the number of nickels in the payment
@param pennies the number of pennies in the payment
*/
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;
}


/**
Computes the change due and resets the machine for the next customer.
@return the change due to the customer
*/
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;
}


-------------------------------------------------------------------


public class Coin
{
public Coin()
{
value = 0;
valueone = 0;
name = " ";
}
public Coin(double v, double m, String n)
{
value = v;
valueone = m;
name = n;
}
public Coin(String n)
{
name = n;
}
public double getValue()
{
double total = value + valueone;
return total;


}
public String getName()
{
return name;
}


public static final double ONECENTEURO_vALUE = .01;
public static final double TWOCENTEURO_VALUE = .02;
public static final double FIVECENTEURO_vALUE = .05;
public static final double TENCENTEURO_VALUE = .10;
public static final double TWENTYCENTEURO_VALUE = .20;
public static final double FIFTYCENTEURO_VALUE = .50;
public static final double ONE_EURO_VALUE = 1.00;
public static final double TWO_EURO_VALUE = 2.00;



private double value;
private double valueone;
private String name;
}


--------------------------------------------------------------------


import java.util.Scanner;


/**
This program simulates a transaction in which a user pays for an item
and receives change.
*/
public class CashRegisterSimulator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);


CashRegister register = new CashRegister();


System.out.print("Enter price: ");
double price1 = in.nextDouble();
register.recordPurchase(price1);
System.out.print("Enter price: ");
double price2 = in.nextDouble();
register.recordPurchase(price2);


System.out.print("Enter dollars: ");
int dollars = in.nextInt();
System.out.print("Enter quarters: ");
int quarters = in.nextInt();
System.out.print("Enter dimes: ");
int dimes = in.nextInt();
System.out.print("Enter nickels: ");
int nickels = in.nextInt();
System.out.print("Enter pennies: ");
int pennies = in.nextInt();
register.enterPayment(dollars, quarters, dimes, nickels, pennies);


System.out.print("Your change: ");
System.out.println(register.giveChange());
}
}

That's what i have so far and really have no idea what to do next. Any help would be appreciated, thanks!!!

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
9
Views
6 Years
Discussion Span
Last Post by DragonMa
0

I am also stuck on this assignment, please let me know if you have figured it out

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.