Advertisement
illpastethat

Make Change.java ttam_

Feb 7th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. /*
  2. File : Change.java
  3. Author: G.J. Grevera
  4. Desc. : Purchase an item and make change.
  5. */
  6. import java.util.Scanner;
  7.  
  8. public class Change {
  9.  
  10.   public static void main ( String args[] ) {
  11.     //get ready to read from the keyboard
  12.     Scanner in = new Scanner( System.in );
  13.     //prompt for the price
  14.     System.out.print( "Enter price of an item: " );
  15.     //get the price
  16.     int price = in.nextInt();
  17.  
  18.     //calculate change
  19.     int change = 100 - price;
  20.     int quarters = change / 25;
  21.     change = change - quarters * 25;
  22.     int dimes = change / 10;
  23.     change = change - dimes * 10;
  24.     int nickels = change / 5;
  25.  
  26.     //report results (change)
  27.     System.out.println( "You bought an item for " + price +
  28.     " cents and gave me a dollar so your change is:" );
  29.     System.out.println( "\t" + quarters + " quarters," );
  30.     System.out.println( "\t" + dimes + " dimes, and" );
  31.     System.out.println( "\t" + nickels + " nickels" );
  32.  
  33.   }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement