2. Write a program that will simulate a Gas station cash register where the item
ID: 3640427 • Letter: 2
Question
2. Write a program that will simulate a Gas station cash register where the items being sold is limited to the following: (1) Diesel (2) Unleaded Gasoline (3) Premium Gasoline (4) Liquefied Petroleum Gas.Consider five (5) customers who would refill their gasoline tanks or but an LPG. Your program should ask for the type of products they will avail. For computation purposes, diesel is 46.00 per liter, Unleaded Gasoline is 55.45 per liter, Premium Gasoline is 60.25 per liter, while LPG is 755.00 per 11 kilogram tank
Your program will ask for the number of liters purchase if gasoline will be availed while if the choice of product is LPG, the program should ask for the number of tanks to be purchased.
Your program output should be the total sales of the five customers with the detailed breakdown of the sales of the five customers.
Explanation / Answer
import java.util.*; import java.io.*; class GasolineCashRegister{ private double diesel=46.00; private double ungasoline=55.45; private double prgasoline=60.25; private double lpg=755.00; private int litres; private int tanks; private int choice; static double sum2; Scanner sc= new Scanner(System.in); private int cont; public void calculate(){ double sum=0.0; double sum1=0.0; int count=1; do{ System.out.println("Enter the choice of fuel"); choice= sc.nextInt(); switch(choice){ case 1: { System.out.println("diesel"); litres=sc.nextInt(); sum=litres*diesel; System.out.println("The diesel amt is "+sum); break; } case 2: { System.out.println("ungasoline"); litres=sc.nextInt(); sum=litres*ungasoline; System.out.println("The ungasoline amt is "+sum); break; } case 3: { System.out.println("prgasoline"); litres=sc.nextInt(); sum=litres*prgasoline; System.out.println("The prgasoline amt is "+sum); break; } case 4: { System.out.println("lpg"); tanks=sc.nextInt(); sum=tanks*lpg; System.out.println("The lpg amt is "+sum); break; } } sum1=sum1+sum; System.out.println("enter 1 if the same customer is taking any other product else press 0"); cont=sc.nextInt(); } while(cont==1 && countRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.