Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- Code :
- import java.util.Scanner;
- public class Change {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- //variables that will hold the data for the cashier
- double cash;
- double cost;
- double tax;
- double change;
- double t;
- double total;
- //input the cost
- System.out.print("Enter the cost : ");
- cost = sc.nextDouble();
- //input the money tendered
- System.out.print("Enter the money tendered : ");
- cash = sc.nextDouble();
- //conversions
- t = 0.06;
- //tax computation
- tax = cost*t;
- //change computation
- total = cost-tax;
- change = cash-cost;
- //output
- System.out.println("Cash Tendered : " + cash);
- System.out.println("Tax : " + tax);
- System.out.println("Total : " + total);
- System.out.println("Change : " + change);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement