173k views
4 votes
Puma Filling Station sells gasoline and has a car wash. Fees for the car wash are K40.00 with a gasoline purchase of K200.00 or more and K70.00 otherwise. Three kinds of gasoline are available: regular at K16.25, unleaded at K 17.63, and super unleaded at K 19.50 per litter. You are required to write a program that prints a statement for a customer. Input consists of number of litters purchased, kind of gasoline purchased (R, U, S, or for no purchase, N), and car wash desired (Y or N). Develop a Pseudocode and a structure chart for the service station problem.

User Edu Ruiz
by
5.2k points

1 Answer

4 votes

Answer:

1. Code:

import java.util.*;

public class serviceStation

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

//User inputs

System.out.println("Enter the litres of gasoline you want: ");

int gas =sc.nextInt();

System.out.println("Enter the type of gasoline \\R->regular \\U->unleaded \\S->super unleaded \\N->none");

char type = sc.next().charAt(0);

//Convert the character inputs to lowercase

type = Character.toUpperCase(type);

System.out.println("Car wash desired? (Y or N)");

char wash = sc.next().charAt(0);

//Convert the character inputs to lowercase

wash = Character.toUpperCase(wash);

String s1 = "" ,s2 = "";

//Check for type of gas

double total = 0.0;

if(type == 'R')

{

total = total + gas* 16.25;

s1 = "Regular";

}

else if(type == 'U')

{

total = total + gas*17.63 ;

s1 = "Unleaded";

}

else if(type == 'S')

{

total = total + gas*19.50 ;

s1 = "Super Unleaded";

}

else if(type == 'N')

{

total = total + gas*0 ;

s1 = "No gas taken";

}

double fees = 0.0;

//Check if wash is desired

if(wash == 'Y')

{

if(total >= 200)

{

fees = total + 40.0;

s2 = "Yes";

}

else

{

fees = total + 70.0;

s2 = "Yes";

}

}

else

{

fees = total;

s2 = "No";

}

//print billing details

System.out.println("\\ Billing Details:");

System.out.println("Litres of Gasoline: " + gas);

System.out.println("Type of Gasoline: " + s1);

System.out.println("Car Wash desired: " + s2);

System.out.println("Total Cost: K" + fees);

Step-by-step explanation:

User Iscream
by
5.1k points