Advertisement
StefanTobler

Assignment 2

Sep 20th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. /*
  2.  *
  3.  * Sample Run:
  4.  *  Please Enter the Amount Paid:
  5.  *  5.00
  6.  *  Please Enter the Cost of the Item:
  7.  *  4.57
  8.  *  Change Owed: 0.43
  9.  *  Pennies: 3
  10.  *  Nickels: 1
  11.  *  Dimes: 1
  12.  *  Quarters: 1
  13.  *
  14.  */
  15.  
  16. import java.io.*;
  17. import static java.lang.System.*;
  18.  
  19. import java.util.Scanner;
  20.  
  21. import java.lang.Math;
  22.  
  23. class Main{
  24.  
  25.      public static void main (String str[]) throws IOException {
  26.        Scanner scan = new Scanner (System.in);
  27.        System.out.println("Please Enter the Amount Paid:");
  28.        double x = scan.nextDouble();
  29.        System.out.println("Please Enter the Cost of the Item:");
  30.        double y = scan.nextDouble();
  31.        double z = ((double)((Math.round(x * 1000)) - (Math.round(y * 1000)))/1000);
  32.        int pennies = ((int)((100*z))%5);
  33.        int quarters = (int)((z*100)/25);
  34.        int dimes = (int)(((z*100)-quarters*25)/10);
  35.        int nickels = (int)(((z*100)-(quarters*25)-(dimes*10))/5);
  36.        System.out.println("Change Owed: " + z);
  37.        System.out.println("Pennies: " + pennies);
  38.        System.out.println("Nickels: " + nickels );
  39.        System.out.println("Dimes: " + dimes);
  40.        System.out.println("Quarters: " + quarters);
  41.        
  42.        scan.close();
  43.        
  44.        
  45.        }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement