Advertisement
virtualideaz

Change.java

Nov 26th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1.  Write a java program that calculates the change for a cashier. The program will request the cost of the item. The user then types in the cost. The program then outputs the cost of the item including the sales tax (use 6% as the sales tax value). The program next requests and receives the amount tendered by the costumer. Finally the program outputs a summary of all figures, including the amount of changes due to the costumer. Name the program Change.java
  2.  
  3. Code :
  4.  
  5. import java.util.Scanner;
  6. public class Change {
  7.  
  8. static Scanner sc = new Scanner(System.in);
  9. public static void main(String[] args) {
  10.  
  11.         //variables that will hold the data for the cashier
  12.  
  13.         double cash;
  14.         double cost;
  15.         double tax;
  16.         double change;
  17.         double t;
  18.         double total;
  19.  
  20.         //input the cost
  21.             System.out.print("Enter the cost : ");
  22.             cost = sc.nextDouble();
  23.  
  24.        //input the money tendered
  25.             System.out.print("Enter the money tendered : ");
  26.             cash = sc.nextDouble();
  27.  
  28.        //conversions
  29.             t = 0.06;
  30.  
  31.        //tax computation
  32.             tax = cost*t;
  33.  
  34.        //change computation
  35.             total = cost-tax;
  36.             change = cash-cost;
  37.  
  38.  
  39.        //output
  40.             System.out.println("Cash Tendered : " + cash);
  41.             System.out.println("Tax : " + tax);
  42.             System.out.println("Total : " + total);
  43.             System.out.println("Change : " + change);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement