Question

In: Computer Science

Write a Java application for a gas station to calculate the total payment for customer. Your...

Write a Java application for a gas station to calculate the total payment for customer.

Your program should display a menu and get customer’s input: ****************************

Welcome to XYZ gas station! Select type of gas (enter R, P, S) Regular - R. plus - P. Super -S: ****************************

Enter the amount of gas in gallons:

In your code, define regular price: $2.45, plus: $2.65, super $2.95 as constant.

Use 7% as sale tax.

Calculate gas subtotal = sale price * gas amount Tax=subtotal * sale tax. Total payment = subtotal + Tax Output nicely to customer the total amount payment:

######################################################

Your payment for (Regular/plus/Super) is $###.

######################################################

Requirements:

Use switch statement for type of gas (case ‘R’, case ‘P’, case ‘S’ , etc)

Use while loop to display the menu. If user inputs anything other than R,P,S, display the menu again.

Use for loop statement to draw lines(**********… and ##############...)

Solutions

Expert Solution

import java.util.Scanner;

public class GasStation {

  
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// declarations
double reg = 2.45, plus = 2.65, sup = 2.95;
double saleTax = 0.07;
double gasSubtotal = 0.0;
double tax = 0.0;
double totalPayement = 0.0;
char ch;
do{ // menu until valid input is not given
for (int i = 0; i < 30; i++) {
System.out.print("*");
}
System.out.println("\nWelcome to XYZ gas station!");
for (int i = 0; i < 30; i++) {
System.out.print("*");
}
  
System.out.print("\nSelect type of gas (enter R, P, S) Regular - R. plus - P. Super -S: ");
ch = sc.next().charAt(0);
if(ch == 'R'||ch =='S'|| ch =='P') break; // only break when input is correct
}while(true);
System.out.print("Enter the amount of gas in gallons: ");
double gasAmount = sc.nextDouble(); // take amount
switch(ch){
case 'R': gasSubtotal = reg * gasAmount;
tax = gasSubtotal * saleTax;
totalPayement = gasSubtotal + tax;
break;
case 'P': gasSubtotal = plus * gasAmount;
tax = gasSubtotal * saleTax;
totalPayement = gasSubtotal + tax;
break;
case 'S': gasSubtotal = sup * gasAmount;
tax = gasSubtotal * saleTax;
totalPayement = gasSubtotal + tax;
break;
}
System.out.println("");
for (int i = 0; i < 50; i++) {
System.out.print("#");
}
System.out.println("\nYour payment for (Regular/plus/Super) is $"+totalPayement);
for (int i = 0; i < 50; i++) {
System.out.print("#");
}
System.out.println("");
}
  
}

/* OUTPUT */

/* PLEASE UPVOTE */


Related Solutions

Develop a Java application using Parboiled library to write aparser for a customer form. Your...
Develop a Java application using Parboiled library to write a parser for a customer form. Your program should include a grammar for the parser and display the parse tree with no errors.The customer form should include the following structure:First name, middle name (optional), last nameStreet address, city, state (or province), countryPhone numberRules• First name, middle name and last name should start with an uppercase letter followed by lower case letters. Middle name is an optional input meaning such an input...
Using Python write an application that will calculate a loan payment. To complete this, you are...
Using Python write an application that will calculate a loan payment. To complete this, you are required to write 2 functions, LoanPayment and InterestOnlyLoanPayment, as well as a test application that calls each of the functions to get the payment amount based on parameters supplied to the functions. The test application should output both the loan payment and the interest-only loan payment based on input values from the user. The LoanPayment function is defined as follows: Payment = Loan amount...
A gas station wants a program to keep track of sales. Your gas station sells diesel...
A gas station wants a program to keep track of sales. Your gas station sells diesel for 107.9 cents per litre and regular gas for 112.9 cents per litre. Have the user enter the type of fuel (1 = Regular gas, 2 = Diesel) and number of litres sold. Print out a total for each sale (remember fuel prices already include the GST). Once you enter a 0 for the type of fuel your program should stop and print out...
Although gas station owners lock their tanks at night, a gas station owner in your neighborhood...
Although gas station owners lock their tanks at night, a gas station owner in your neighborhood was the victim of theft because his employee had a key to the tank. The owner of the gas station wants to bury the gasoline so deep that no vacuump pump, no matter how powerful, will be able to extract it. He has hired you as a general contractor to dig the holes for the tanks. What is the minimum depth needed for the...
A gas station sold a total of 8019 gallons of gas on nine randomly picked days....
A gas station sold a total of 8019 gallons of gas on nine randomly picked days. Suppose the amount sold on a day is normally distributed with a true standard deviation σ = 90. Can you conclude that the true mean amount of gas sold on a day is less than 900 gallons? Use α = 0.05
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark...
Write a Java program in Eclipse to calculate the total cost to enter into a waterpark for a family/group Ticket rates are listed below kids (Age 12 and under)=$ 12.50 Regular( Age between12 -55) =$ 18.25 Seniors (55 and above) = $15.00 Tax =7% Your program should ask the user to enter the total number of members in their group. User needs to enter the ages for all members. Write appropriate error messages for invalid entries. An array should be...
In Java write an application that calculates total retail values for 5 different shoes entered by...
In Java write an application that calculates total retail values for 5 different shoes entered by the user. Shoe 1 $15.50 Shoe 2 $27.30 Shoe 3 $34.50 Shoe 4 $42.11 Shoe 5 $54.25 Application must read shoe number and quantity sold for each product stdin, compute the total value of that sale, and add the value of that sale to a grand total for that shoe. After all data has been entered, display the total value of each of the...
Write a java application that implements ArrayStack in chapter 16 of your textbook.
Write a java application that implements ArrayStack in chapter 16 of your textbook. Your application should have two files: 1. ArrayStack.java: This file will have the implementation of your stack. 2. TestStack.java: This file will have the main method where you declare your stack object and test the different stack operations. In addition to the ArrayStack methods given in the book, you are to write a toString method. This will allow you to print the Stack object from main. You...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total number of numbers in the file, Calculate the sum of all the numbers in the file, Calculate the average of all the numbers in the file, Find the smallest value of all the numbers in the file, Find the largest value of all the numbers in the file, Calculate the standard deviation of all the numbers in the file
You are the manager of a gas station and your goal is to maximize profits.
You are the manager of a gas station and your goal is to maximize profits. Based on your past experience, the elasticity of demand by Texans for a car wash is -4, while the elasticity of demand by non-Texans for a car wash is -6. If you charge Texans $20 for a car wash, how much should you charge a man with Oklahoma license plates for a car wash?$1.50$15.00$18.00$20.00
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT