Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write your program in a java file called CoinMachine.java. This means, the name of class in this file must be CoinMachine. Your program must determine
Write your program in a java file called CoinMachine.java. This means, the name of class in this file must be CoinMachine. Your program must determine the amount of change that would be returned by a coin machine given the amount of money dropped into the machine by a customer (call it the cash) and the cost of the item wanted by the customer (call it the price). Assume the input parameters (cash and price) are received through program arguments, i.e., main(String[] args) method will receive cash in args[0] and price in args[1]. Assume that the change will be composed of toonies, loonies, quarters, dimes, and nickels. Assume also that: The amount of money dropped into the machine by the customer will always be equal to or greater than the cost of the item. . Amounts are considered to be integer amounts in cents. For example, $2.75 is represented by the integer 275. . Amounts will always be multiples of 5 (i.e., pennies are not considered). Your coin machine has an infinite number of each type of coin with which to supply change. Note that, to be considered correct, your program must provide the user with the most convenient exact change (i.e., the exact amount with the fewest coins). Write Java code to display the following information: 1. The amount received by the coin machine. 2. The cost of the item. 3. The required change. 4. How many of each of the coins will be returned by the coin machine. Input Arguments Note that this program is run by providing input arguments. That is, cash and price do not have a fixed value. Their values will depend on the input provided when running the program. For example, once this program is compiled, it can be run by typing the text run CoinMachine 400 215 in the Interactions Pane and pressing Enter. The output of the program must be different than if the text run CoinMachine 500 150 was entered
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