Question
The cash register will then display the UPC, product name and unit price. A cashier uses a scanner to enter the Universal Product Code (UPC)
The cash register will then display the UPC, product name and unit price.
A cashier uses a scanner to enter the Universal Product Code (UPC) for products bought.
After the last product is scanned, the cashier presses the "Pay" button. The cash register displays the total. The buyer hands over cash and the cash register displays the receipt on the screen (item name, UPC, and price for each, followed by the total price). To simulate this application, the user will enter the UPCs on the terminal (use a Scanner object). Output from the cash register is displayed on the terminal, using the System.out object.
Implement in Java and test your code. Hardcode several default products in a product inventory (e.g. prod: "Snickers bar", UPC: 101, Unit price: $1). Assume an infinite supply of products.
*UPC are already stored
*Display list with (UPC, price, product name) and user is able to enter UPC to buy items (loop can be used to ask user if they want to buy another item)
* once user is done selecting items, display the total
*The buyer hands over cash and the cash register displays the receipt on the screen (item name, UPC, and price for each, followed by the total price).
IT IS A JAVA CASH REGISTER APPLICATION
Please finish the coding and test it
import java.util.Scanner;
public class UPCScanner { static double price=0; static String signal=""; static int count=1; static String prod[]=new String[5]; public static void main(String args[]) { int quantity=0; String item_code=""; System.out.println("S_no Products Item_code\t Unit price"); System.out.println(" 1 Snickers bar\t UPC: 101\t $1"); System.out.println(" 2 Toast\t UPC: 102\t $2"); System.out.println(" 3 Biscuit\t UPC: 103\t $2"); System.out.println(" 4 Chocolate\t UPC: 104\t $5"); System.out.println(" 5 Book\t UPC: 105\t $6"); while(signal.equals("pay")!=true||signal.equals("")) { signal=cash_pay(item_code,quantity); System.out.println("Enter your item code"); Scanner scan = new Scanner(System.in); item_code=scan.nextLine(); System.out.println("Enter number of units for above item: "); quantity=scan.nextInt(); } } public static String cash_pay(String item_code, int unit) { count++; if(item_code.equals("UPC: 101")) price=unit*1; if(item_code.equals("UPC: 102")) price=unit*2; if(item_code.equals("UPC: 103")) price=unit*2; if(item_code.equals("UPC: 104")) price=unit*5; if(item_code.equals("UPC: 105")) price=unit*6; if(signal.equals("pay")!=true) { System.out.println("Enter any key to enter more type 'pay' to make bill: "); Scanner sc=new Scanner(System.in); signal=sc.nextLine(); } else { cash_payment(item_code, unit); } return signal; } public static void cash_payment(String item_code, int unit) { prod[count]=item_code; if(signal.equals("pay")==true) { System.out.println("S_no Item_code Units Total price"); System.out.println(count+" "+prod[count]+" "+unit+" "+price); } }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started