Assignment #2ObjectiveIn this assignment you will write an application that converts a monetary amount to a bills and cash representation. Project Specifications1. Provide a test program called Assignment2. 2. Use comments to show your name, the date and the assignment number. 3. Use the Scanner class to read a value representing a monetary amount. 4. Determine the fewest number of each bill and coins needed to represent the amount. 5. Start with the biggest bill. For this assignment use bills of $10, $5 and $1, and all coins. 6. For example, if the user enters 47.63 dollars, your program will display the following: Due Date:Submit your *.java file through Blackboard no later than Sep 28 by 11:59 pm.IMPORTANT SUBMISSION INSTRUCTIONS:1. In blackboard click on Assignments – Assignment2 – at the bottom of the document click on View/Complete Assignment: A2 to upload your file. 2. Use the BROWSE button to find the file. Select it and click on the Submit button. If you have trouble with this assignment PLEASE come to see me! | ||
A2 >> View/Complete Assignment: A2 | ||
Solution import java.util.Scanner; public class Assignment2 { //----------------------------------------------------------------- // Reads a monetary amount and computes the equivalent in bills // and coins. //----------------------------------------------------------------- public static void main (String[] args) { final int CENTS_IN_TEN_DOLLARS = 1000; final int CENTS_IN_FIVE_DOLLARS = 500; final int CENTS_IN_ONE_DOLLAR = 100; final int CENTS_IN_QUARTER = 25; final int CENTS_IN_DIME = 10; final int CENTS_IN_NICKEL = 5; double total; int tens, fives, ones, quarters, dimes, nickels; Scanner scan = new Scanner(System.in); System.out.print ("Enter monetary amount: "); total = scan.nextDouble(); int remainingCents = (int) (total * 100); tens = remainingCents / CENTS_IN_TEN_DOLLARS; remainingCents %= CENTS_IN_TEN_DOLLARS; fives = remainingCents / CENTS_IN_FIVE_DOLLARS; remainingCents %= CENTS_IN_FIVE_DOLLARS; ones = remainingCents / CENTS_IN_ONE_DOLLAR; remainingCents %= CENTS_IN_ONE_DOLLAR; quarters = remainingCents / CENTS_IN_QUARTER; remainingCents %= CENTS_IN_QUARTER; dimes = remainingCents / CENTS_IN_DIME; remainingCents %= CENTS_IN_DIME; nickels = remainingCents / CENTS_IN_NICKEL; remainingCents %= CENTS_IN_NICKEL; System.out.println ("That's equivalent to:"); System.out.println (tens + " ten dollar bills"); System.out.println (fives + " five dollar bills"); System.out.println (ones + " one dollar bills"); System.out.println (quarters + " quarters"); System.out.println (dimes + " dimes"); System.out.println (nickels + " nickels"); System.out.println (remainingCents + " pennies"); } } |
I am student of CIS at - Massachusetts Bay College - Massbay, Wellesley, MA. I would like to share some of my classes, so who is interested in learn computation, feel free to copy, and exchange information. Também falo português e hablo un poquito del español. Nil, 12/11/2010
Total de visualizações de página
sábado, 11 de dezembro de 2010
In this assignment you will write an application that converts a monetary amount to a bills and cash representation.
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário