Advertisement
Guest User

ComputeChange.java

a guest
Apr 26th, 2012
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ComputeChange {
  4. public static void main(String[] args) {
  5. // Create a Scanner
  6. Scanner input = new Scanner(System.in);
  7.  
  8. // Receive the amount
  9. System.out.print(
  10. "Enter an amount in double, for example 11.56: ");
  11. double amount = input.nextDouble();
  12.  
  13. int remainingAmount = (int)(amount * 100);
  14.  
  15. // Find the number of one dollars
  16. int numberOfOneDollars = remainingAmount / 100;
  17. remainingAmount = remainingAmount % 100;
  18.  
  19. // Find the number of quarters in the remaining amount
  20. int numberOfQuarters = remainingAmount / 25;
  21. remainingAmount = remainingAmount % 25;
  22.  
  23. // Find the number of dimes in the remaining amount
  24. int numberOfDimes = remainingAmount / 10;
  25. remainingAmount = remainingAmount % 10;
  26.  
  27. // Find the number of nickels in the remaining amount
  28. int numberOfNickels = remainingAmount / 5;
  29. remainingAmount = remainingAmount % 5;
  30.  
  31. // Find the number of pennies in the remaining amount
  32. int numberOfPennies = remainingAmount;
  33.  
  34. // Display results
  35. System.out.println("Your amount " + amount + " consists of \n" +
  36. "\t" + numberOfOneDollars + " dollars\n" +
  37. "\t" + numberOfQuarters + " quarters\n" +
  38. "\t" + numberOfDimes + " dimes\n" +
  39. "\t" + numberOfNickels + " nickels\n" +
  40. "\t" + numberOfPennies + " pennies");
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement