Name:h Wu CSC 109 Description: Write the pseudocode for an application that will
ID: 3761844 • Letter: N
Question
Name:h Wu CSC 109 Description: Write the pseudocode for an application that will determine the cost of parking in the On Center Parking Lot. Trucks are charged $2.50/hr and cars are charged $1.75/hr. Input the type of vehicle (T or C) and the number of minutes parked. If a vehicle parks for part of an hour charge them the entire hour. Display a customer receipt including the vehicle type, the number of hours parked,th parking rate and the final cost. If the user inputs something other than T or C for the vehicle type display an error message and loop back to the beginning n ud nol hunacter Vehicle tupe bodon OkExplanation / Answer
/***The java program that prompts user to enter type of vehicle
* If user enter invalid type, then re prompt for vehicle type.
* Prompt number of hours parked and print the vechicle details
* and final cost of parking*/
//ParkingCost.java
import java.util.Scanner;
public class ParkingCost
{
public static void main(String[] args)
{
//cretae an object of Scanner class
Scanner scanner=new Scanner(System.in);
//set cost of parking rates
final double TRUCKS=2.50;
final double CARS=1.75;
//declare variables
double finalCost=0; //to calculate final cost
char vehicleType; //to read vehicle type
String vehicle="";//To set vehicele type
double hours=0; //to read hours of parking
double parkingRate=0; //To calculate parking rate
do
{
//read input type of vehicle
System.out.println("Enter type of vehicle ( T or C)");
vehicleType=scanner.nextLine().charAt(0);
//print an error message if invalid type
if(vehicleType!='T' && vehicleType!='C')
System.out.println("Invalid type of vehicle");
}while((vehicleType!='T' && vehicleType!='C'));
System.out.println("Number of hours parked ");
//read number of hours
hours=scanner.nextDouble();
//Get total hours if parked part of hour
//get whole number of near value of hours entered
hours=Math.ceil(hours);
if(vehicleType=='T')
{
vehicle="TRUCK";
parkingRate=TRUCKS;
//calculate final cost of truck parking
finalCost=hours*TRUCKS;
}
else if(vehicleType=='C')
{
vehicle="CAR";
parkingRate=CARS;
//calculate final cost of car parking
finalCost=hours*CARS;
}
//print vehicle parking cost details
System.out.println("Vechicle Type:"+vehicle);
System.out.println("Hours parked :"+hours);
System.out.println("Parking Rate :"+parkingRate);
System.out.println("Total Cost :"+finalCost);
}
}//end of the class
-------------------------
Sample output:
sample run1
Enter type of vehicle ( T or C)
T
Number of hours parked
10
Vechicle Type:TRUCK
Hours parked :10.0
Parking Rate :2.5
Total Cost :25.0
sample run2
Enter type of vehicle ( T or C)
S
Invalid type of vehicle
Enter type of vehicle ( T or C)
C
Number of hours parked
10.5
Vechicle Type:CAR
Hours parked :11.0
Parking Rate :1.75
Total Cost :19.25
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.