Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. public class Sales {
  2.     public static void main (String[] args) {
  3.        
  4.         System.out.println("What is the total sales charge");
  5.         double tsales = IO.readDouble();
  6.        
  7.         System.out.println("How much is the customer giving");
  8.         double paid = IO.readDouble();
  9.        
  10.         if (paid < tsales) {
  11.             IO.reportBadInput();
  12.             return;
  13.         }
  14.        
  15.         int twenty = 0;
  16.         int ten = 0;
  17.         int five = 0;
  18.         int one = 0;
  19.         int quarter = 0;
  20.         int dime = 0;
  21.         int nickel = 0;
  22.         int penny = 0;
  23.        
  24.         double owe = paid - tsales;
  25.        
  26.         if (owe > 20) {
  27.             while (owe > 20) {
  28.                 twenty ++;
  29.                 owe = owe - 20;
  30.             }
  31.            
  32.             System.out.println(twenty + " $20 bills");
  33.         }
  34.        
  35.         if (owe > 10) {
  36.             while (owe > 10) {
  37.                 ten ++;
  38.                 owe = owe - 10;
  39.             }
  40.            
  41.             System.out.println(ten + " $10 bills");
  42.         }
  43.        
  44.         if (owe > 5) {
  45.             while (owe > 5) {
  46.                 five ++;
  47.                 owe = owe - 5;
  48.             }
  49.            
  50.             System.out.println(five + " $5 bills");
  51.         }
  52.        
  53.         if (owe > 1) {
  54.             while (owe > 1) {
  55.                 one ++;
  56.                 owe = owe - 1;
  57.             }
  58.            
  59.             System.out.println(one + " $1 bills");
  60.         }
  61.        
  62.         if (owe > 0.25) {
  63.             while (owe > 0.25) {
  64.                 quarter ++;
  65.                 owe = owe - 0.25;
  66.             }
  67.            
  68.             System.out.println(quarter + " Quarters");
  69.         }
  70.        
  71.         if (owe > 0.10) {
  72.             while (owe > 0.10) {
  73.                 dime ++;
  74.                 owe = owe - 0.10;
  75.             }
  76.            
  77.             System.out.println(dime + " Dimes");
  78.         }
  79.        
  80.         if (owe > 0.05) {
  81.             while (owe > 0.05) {
  82.                 nickel ++;
  83.                 owe = owe - 0.05;
  84.             }
  85.            
  86.             System.out.println(nickel + " Nickels");
  87.         }
  88.        
  89.         if (owe > 0.01) {
  90.             while (owe > 0.01) {
  91.                 penny ++;
  92.                 owe = owe - 0.01;
  93.             }
  94.            
  95.             System.out.println(penny + " Pennies");
  96.         } else{
  97.            
  98.             System.out.println("No Bills");
  99.         }
  100.        
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement