Question
This is Java Title: Money, money, money Terms: change format - 0 hundreds, 5 tens, 0 fives, 2 ones, 1 quarter, 1 dime, 0 nickels,
This is Java
Title: Money, money, money
Terms:
- change format - 0 hundreds, 5 tens, 0 fives, 2 ones, 1 quarter, 1 dime, 0 nickels, 0 pennies
- dollar format - $52.35
- float format - 52.35
- check format - fifty two dollars and 35 cents
Problem: Money can be represented in various formats. For example, $52.35, fifty two dollars and thirty five cents or even 5 tens, 2 ones, 1 quarter and 10 cents. All of these formats represent the same amount, 52.35. Fast food restaurants have an ongoing challenge of training young employees how to handle dealing with money in its various formats - making change, knowing how much to charge for something, understanding the relationship between a number, like 52.35, and the various ways of representing that amount using the US monetary system. They need your help training the next generation of workers until these somewhat simplistic jobs are turned over to robots.
The currency in each store consists of only hundreds, tens, ones, quarters, dimes, nickels and pennies. Make the least amount of change possible. For example, $11.25 should be 1 ten, 1 one, 1 quarter.
- when you see the word "change" take in the change format, output in dollar format
- when you see the word "float" take in the float format, output in change format
- when you see the word "check" take in the float format, output in check format
- when you see the word "change-change" take in the amount given by the customer in change format and the cost of the transaction in float format, output the amount to be given to the customer in dollar & change format
- when you see the word "change-float" take in the amount given by the customer in float format and the cost of the transaction in float format, output the amount to be given to the customer in dollar and change format
In the repository you will find 2 starting files along with several test files as follows:
- testMoney.java - the main test driver that handles reading in the command and calling the appropriate money method
- Money.java - the Money class which is where you will place all of your code
- testFloat.txt - several "float" command tests
- testChange.txt - several "change" command tests
- testChangeChange.txt - several "change-change" command tests
- testChangeFloat.txt - several "change-float" command tests
- testCheck.txt - several "check" command tests
- testAll.txt - several different command tests
Sample test data:
change 0 5 0 2 1 1 1 5 change 3 8 0 0 0 99 1 3 float 427.99 float 25.33 check 32.18 check 100 change-float 100.00 52.17 change-change 1 0 0 0 0 0 0 52.17 change 1 1 1 1 1 1 1 change-float 5 .99 change-float 100 .01
Sample output:
0 hundreds 5 tens 0 fives 2 ones 1 quarters 1 dimes 1 nickels 5 pennies = $52.45 3 hundreds 8 tens 0 fives 0 ones 0 quarters 99 dimes 1 nickels 3 pennies = $389.98 $427.99 = 4 hundreds 2 tens 1 fives 2 ones 3 quarters 2 dimes 0 nickels 4 pennies $25.33 = 0 hundreds 2 tens 1 fives 0 ones 1 quarters 0 dimes 1 nickels 3 pennies check for $32.18 = 32 dollars and 18 cents check for $100.00 = 100 dollars and 0 cents change back on $100.00 for purchase of $52.17 is $47.83 which is 0 hundreds 4 tens 1 fives 2 ones 3 quarters 0 dimes 1 nickels 3 pennies change back on 1 hundreds 0 tens 0 fives 0 ones 0 quarters 0 dimes 0 nickels 0 pennies for purchase of $52.17 is $47.83 which is 0 hundreds 4 tens 1 fives 2 ones 3 quarters 0 dimes 1 nickels 3 pennies 1 hundreds 1 tens 0 fives 1 ones 1 quarters 1 dimes 1 nickels 1 pennies = $111.41 change back on $5.00 for purchase of $0.99 is $4.01 which is 0 hundreds 0 tens 0 fives 4 ones 0 quarters 0 dimes 0 nickels 1 pennies change back on $100.00 is $99.99 0 hundreds 9 tens 1 fives 4 ones 3 quarters 2 dimes 0 nickels 4 pennies.
Be sure to take notice of the output format for each command. Your program must follow the exact format presented above.
- For a grade of A your program must support change, change-change, float, change-float
- For a grade of B your program must support change, change-change, float
- For a grade of C your program must support change
- For extra credit your program must support everything
Starting code that you will add on to:
/******** Program: Money class - program assignment #1 ********/
import java.util.*; import java.text.*;
public class Money { // declare class variables double total; // used to store the Money value as a double precision floating point number like 34.2 // you will need more variables declared here to handle each of the currency types; for example int hundreds to keep track of how many hundred dollar bills // this one will help you print floating point values in US currency format like $10.50 NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
// convert current currency values to a string public String toString() { }
// converts amount to US currency format public String toCurrency(double amount) { return nf.format(Math.round(amount * 100.0) / 100.0); } // convert currency to float // read currency values from Scanner s and compute value // output results public void processChange(Scanner s) { }
// read from Scanner s and process float command // convert float to change // output results public void processFloat(Scanner s) { }
// read from Scanner s and process check command // convert float to dollar words & cents // output results public void processCheck(Scanner s) {
}
// read from Scanner s and process change-float command // read float of customer payment // read float of transaction cost // calculate difference and compute change values // output the results public void processChangeFloat(Scanner s) {
}
// read from Scanner s and process change-change command // read change of customer payment // read float of transaction cost // calculate difference and compute change values // output the results public void processChangeChange(Scanner s) {
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started