question archive Programming challenge description: In JAVA The goal of this question is to design a cash register program
Subject:ManagementPrice:5.87 Bought7
Programming challenge description: In JAVA
The goal of this question is to design a cash register program. Your register currently has the following notes/coins within it:
The aim of the program is to calculate the change that has to be returned to the customer with the least number of coins/notes. Note that the expectation is to have an object-oriented solution - think about creating classes for better reusability.
Input:
Your program should read lines of text from standard input (this is already part of the initial template). Each line contains two numbers which are separated by a semicolon. The first is the Purchase price (PP) and the second is the cash(CH) given by the customer.
Output:
For each line of input print a single line to standard output which is the change to be returned to the customer. If CH == PP, print out Zero. If CH > PP, print the amount that needs to be returned (in terms of the currency values). Any other case where the result is an error, the output should be ERROR.
The output should the change from highest to lowest denomination.
###This is the Code provided###
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class Main {
/**
* Iterate through each line of input.
*/
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(reader);
try { //block of code to be tested
double purchasePrice = Double.parseDouble(in.readLine());
double cash = Double.parseDouble(in.readLine());
Main.calculateChange(purchasePrice, cash);
} catch (Exception e) { // execute if there is an error
System.out.println(e);
}
}
public static void calculateChange(double purchasePrice, double cash) {
// Access your code here. Feel free to create other classes as required
}
}
Purchased 7 times