Q:

Write a Java program that will operate as sale cashier in a supermarket. The program should read items and their prices and print the final bill

0

Write a Java program that will operate as sale cashier in a supermarket. The program should read items and their prices and print the final bill.

For every item in the customer basket, your program should read item name, item price and item quantity, then multiply price and quantity to get subtotal for that item. Your programDo this for all the customer items while adding the subtotals to get the total bill. Your program should stop reading items when you enter “stop” as item name.

Name your class Cashier1

Hint: To compare two String variables s1 and s2 use s1.equals(s2) or s1.equalsIgnoreCase(s2). DO NOT USE s1 == s2

 

Sample Run:

Welcome to the Cashier System

==========================

Enter name: Fish Enter

price: 50

Enter quantity: 3

Subtotal = 150.0 SR

Enter name: Oranges

Enter price: 40

Enter quantity: 2

Subtotal = 80.0 SR

Enter name: Milk Enter price: 10

Enter quantity: 3

Subtotal = 30.0 SR

Enter name: Stop

******************** The Total Bill is 260.0 SR ******************** 

 

=========================================

 

 Modify previous program  to compute the total bill for many customers. After printing the bill for your customer, display a menu asking the user if he/she wants to compute bill for another customer, if the answer is Yes then you should do the same for the new customer. If the answer is No then you should terminate the program. Name your class Cashier2 Sample Run: Welcome to the Cashier System

==========================

Enter item name: Fish

Enter price: 50

Enter quantity: 3

Subtotal = 150.0 SR

Enter name: Oranges

Enter price: 40

Enter quantity: 2

Subtotal = 80.0 SR

Enter name: Milk

Enter price: 10

Enter quantity: 3

Subtotal = 30.0 SR

Enter name: Stop

******************** The Total Bill is 260.0 SR ********************

Is There Another Customer? Yes

Enter name: Meat

Enter price: 50

Enter quantity: 2

Subtotal = 100.0 SR

Enter name: Bananas

Enter price: 20

Enter quantity: 2

Subtotal = 40.0 SR

Enter name: Stop

************************ The Total Bill is 140.0 SR ************************

Is There Another Customer? No

Goodbye…

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Cashier1{
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
double price =0, quantity = 0, subtotal =0, total =0;
String name;
System.out.println("Welcome to the Cashier System");
System.out.print("Enter name: ");
name = kb.next();
while (!name.equalsIgnoreCase("stop")) {
System.out.print("Enter price: ");
price = kb.nextDouble();
System.out.print("Enter quantity: ");
quantity = kb.nextDouble();
subtotal = price * quantity;
total = total + subtotal;
System.out.println("Subtotal = "+subtotal+" SR");
System.out.print("Enter name: ");
name = kb.next();
}
System.out.println("The Total Bill is "+total+" SR");
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now