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...
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...
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
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
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT