Write a program that takes in the amount that the customer’s purchases cost and the amount that the customer paid. It should return the amount of change and how many dollars, twoonies, loonies, quarters, dimes, nickels, pennies are needed to make up the change.
Remember to put comments before major sections of code and to add your title comments at the beginning.
Don't worry if the program gives you numbers to 10 decimal places. That is fine.
Remember comments: title comments and as titles before major sections of the
program.
***************************
* CASH REGISTER
*
***************************
Please enter the total cost: 15.00
Please enter the amount paid: 17.25
Total change: $2.25
You will need:
1 quarter(s)
1 twoonie(s)
***************************
* CASH REGISTER
*
***************************
Please enter the total cost: 10.00
Please enter the amount paid: 11.27
Total change: $1.27
You will need:
2 penny(pennies)
1 quarter(s)
1 loonie(s)
***************************
* CASH REGISTER
*
***************************
Please enter the total cost: 1.00
Please enter the amount paid: 2.83
Total change: $1.83
You will need:
3 penny (pennies)
1 nickel(s)
3 quarter(s)
1 loonies(s)
public class HowManyCents
{
public static void main (String args [])
{
new HowManyCents ();
}
public HowManyCents ()
{//gets money from user with dollars and cents
double amt = IBIO.inputDouble ("Enter the amount in the form $xx.xx >> $");
//converts to cents and to int type
amt = amt * 100;
int cents = (int) amt;
System.out.println ("\n That is " + cents + " cents.");
//Finds the number of loonies in cents, stores it in dollar
int dollar = cents / 100;
//Adjusts the cents so it doesn't hold the dollars too, just the remaining cents
cents = cents % 100;
System.out.println ("Or, " + dollar + " dollars and " + cents + " cents.");
}
}