Need help with Java Question : The CashRegister class has an unfortunate limitat
ID: 3681620 • Letter: N
Question
Need help with Java Question : 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 on Euros and cents. Rather than designing another limited cash register implementation for the European market, you should design a separate Coin class and a cash register that can work with coins of all types. Create a Tester class that will test all of the methods of the Coin class class and CashRegister class.
Explanation / Answer
Tester.java
import java.util.Scanner;
class CashRegister {//this class for dollar transaction
/**
Constructs cash register without arguments
*/
//two cash transaction one in dolars and other is euros
public CashRegister() {
purchase = 0;
payment = 0;
}
//record purchase method contains purchare price as argument
public void Purchase_Amt_in_Dollars(double amount) {
purchase = purchase + amount;
}
/**
Enters the payment received from the customer.
in terms of dollars,quarter,dime,nickel,pennies
* 1dollar=1dollar
* 1quarter=0.25dollar
* 1dime=0.1 dollars
* 1nickel=0.05dollars
* 1pennies=0.01dollars
*/
public void enteryourPayment_in_Dollars(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_Dollars() {//method for change in dollars transaction
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
double QUARTER_VALUE = 0.25;
double DIME_VALUE = 0.1;
double NICKEL_VALUE = 0.05;
double PENNY_VALUE = 0.01;
double purchase;
double payment;
}
class Coin {//this class for euro transaction
Coin() {
value = 0;
valueone = 0;
name = " ";
}
Coin(double v, double m, String n) {
value = v;
valueone = m;
name = n;
}
Coin(String n) {
name = n;
}
public double getValue() {
double total = value + valueone;
return total;
}
public String getName() {
return name;
}
double> double TWOCENTEURO_VALUE = .02;
double FIVECENTEURO_vALUE = .05;
double TENCENTEURO_VALUE = .10;
double TWENTYCENTEURO_VALUE = .20;
double FIFTYCENTEURO_VALUE = .50;
double> double TWO_EURO_VALUE = 2.00;
double purchase;
double payment;
private double value;
private double valueone;
private String name;
//payment in euros
public void enteryourPayment_in_Euros(double ONECENTEURO_vALUE, double TWOCENTEURO_VALUE,
double FIVECENTEURO_vALUE, double TENCENTEURO_VALUE, double FIFTYCENTEURO_VALUE, double ONE_EURO_VALUE, double TWO_EURO_VALUE) {
payment = ONECENTEURO_vALUE * 0.01 + TWOCENTEURO_VALUE * 0.02 + FIVECENTEURO_vALUE * 0.05 + TENCENTEURO_VALUE * 0.10 + TWENTYCENTEURO_VALUE * 0.20 + FIFTYCENTEURO_VALUE * 0.50 + ONE_EURO_VALUE * 1 + TWO_EURO_VALUE * 2;
}
//this methods gives change in euros
public double giveChange_In_Euro() {
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
}
/**
This program simulates a transaction in which a user pays for an item
and receives change.
*/
public class Tester {//driver program
public static void main(String[] args) {
Scanner in = new Scanner(System.in);//keyboard inputting
CashRegister register = new CashRegister();//creating bject
System.out.print("Enter purchased price: in dollars ");
double price2 = in.nextDouble();
register.Purchase_Amt_in_Dollars(price2);//calling method
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.enteryourPayment_in_Dollars(dollars, quarters, dimes, nickels, pennies);
System.out.print("Your change: in dollars ");
System.out.println(register.giveChange_Dollars());
Coin c = new Coin();
System.out.print("Enter purchased price in euros: ");
double price1 = in.nextDouble();
System.out.println("enter no of onecents");
int> System.out.println("enter no of twocents");
int twocent = in.nextInt();
System.out.println("enter no of fivecents");
int fivecent = in.nextInt();
System.out.println("enter no of tencents");
int tencent = in.nextInt();
System.out.println("enter no of twentycents");
int twentycent = in.nextInt();
System.out.println("enter no of fiftycents");
int fiftycent = in.nextInt();
System.out.println("enter no of oneeuros");
int> System.out.println("enter no of twoeuros");
int twoeuro = in.nextInt();
System.out.println("your change in euros : " + c.giveChange_In_Euro());//calling this menthod for euro transaction change
}
}
output
run:
Enter purchased price: in dollars 90
Enter dollars: 90
Enter quarters: 0
Enter dimes: 0
Enter nickels: 0
Enter pennies: 0
Your change: in dollars 0.0
Enter purchased price in euros: 100
enter no of onecents
0
enter no of twocents
0
enter no of fivecents
0
enter no of tencents
0
enter no of twentycents
0
enter no of fiftycents
0
enter no of oneeuros
0
enter no of twoeuros
50
your change in euros : 0.0
BUILD SUCCESSFUL (total time: 51 seconds)