Question
1. A gas station sells three different grades of gasoline. The retail prices are shown below.(Please use java language) Gas Grade Type Price Per Gallon
1. A gas station sells three different grades of gasoline. The retail prices are shown below.(Please use java language)
Gas Grade Type Price Per Gallon
87 Regular $2.45
89 Plus $2.89
93 Premium $3.09
Write a program that asks the user to enter the gas grade and the gallons sold, then calculates and outputs the price before tax.
The program should be menu driven, giving the user various choices:
87 - Regular
89 - Plus
93 - Premium
0 - Exit
You should use a flag-controlled or a sentinel-controlled while loop so that the program can get a series of sales data until the user enters 0. Inside the loop, a switch structure is used to help selecting a gasoline grade and displaying the price for each sale.
Your program should also calculate and display the total value of each grade of gas sold, and calculate and display the total value of all sales. The results should be formatted appropriately.
Here is a sample input/output dialog:
Welcome to "Your Friendly Gas Station"
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 87
Enter the gallons sold: 12.45
The price is $30.50 before tax.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 96
Invalid selection (enter 87, 89, 93, or 0).
Please try again.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 93
Enter the gallons sold: 24.9
The price is $76.94 before tax.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 89
Enter the gallons sold: -12
Gallons sold must be greater than zero.
Try again.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 89
Enter the gallons sold: 12
The price is $34.68 before tax.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 87
Enter the gallons sold: 29.6
The price is $72.52 before tax.
******************************************************
Enter the gas number 87, 89, or 93 to start or 0 to exit.
87 --- Regular $2.45
89 --- Plus $2.89
93 --- Premium $3.09
0 --- Exit
Select a number: 0
Total retail value for each grade of gas sold:
Regular (87): $103.02
Plus (89): $34.68
Premium (93): $76.94
Total retail value of all sales: $214.64
Thank you for using this program!
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