Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Change Coins - java


ChangeCoins Write a program that will take an amount of change, less than $1.00, but more than zero and display the number of quarters, dimes, nickels, and pennies that will be required to make that change. The output must be presented in a descriptive manner that resembles the English language with the following gramatical rules: if the amount is zero, the word "no" should be used. if the amount is 1, the unit must be singular. if the amount is not 1, the unit must be plural. Calculating the Coins To calculate the number of coins, I highly recommend that you convert the amount from dollars (floating point) to cents (integers) because integers are much easier to use for this type of problem. So, if the amount is .93, multiply that amount by 100 to get 93 cents. You will have to use a cast operator to change the amount to integer. See page 64 in your textbook for Conversion between Primitive Data Types. If you use the cast operator incorrectly, you will end up with an error. Hint: multiply the amount by 100 and then convert the answer to integer all in one statement. Do not convert the amount to integer and then multiply by 100 and do not use more than one statement. Once you have the amount in cents as an integer, for our example here, 93 cents. You can then apply the following integer arithmetic to get the quarters in 93 cents: quarters = cents / 25; Attachments
Tags Clarifications


Change Coins


Change Coins Eclipse Project... Attachments (3 K) Download

System.out.print(" dimes, "); } else { System.out.print(" dime, "); } //Print no or number if(nickels == 0){ System.out.print("no"); } else{ System.out.print(nickels); } //Print plural or singular if(nickels == 0 || nickels > 1){ System.out.print(" nickels,

Purchase Answer