Problem Statement A parking garage charges a $5.00 minimum fee to park for up to
ID: 3558244 • Letter: P
Question
Problem Statement
A parking garage charges a $5.00 minimum fee to park for up to three hours. The garagecharges an additional $2.00 per hour for each hour, or part thereof, in excess of threehours. The maximum charge for any given 24-hour period is $15.00.Assume that no car parks for longer than 24 hours.
Specifications
Create 3 files:
ParkingCharges,ParkingChargesTest and ParkingChagesApp
.Use the suffix App (like application) for the class that includes main and the suffix Test for jUnit testclasses.
ParkingCharges:
it has a field called dailyHoursParked. Its type is the interface type List and it isinstantiated with a LinkedList of Double a public static method called calculateCharges. It has one parameter of type double -the hours parked - and it returns the amount charged depending on the hours parked(as described above) Hint: check out the method ceil of class Math Check whether the argument passed is valid (> 0 and <= 24). If not throw anIllegalArgumentExceptionPass the following String to the IllegalArgumentException constructor:
Hours should be > 0 and <= 24
a public method called addHoursParked.
Check whether the argument passed is valid (> 0 and <= 24) If not throw anIllegalArgumentException. Pass the following String to the IllegalArgumentExceptionconstructor:
Hours should be > 0 and <= 24
Otherwise add the hours parked to the field dailyHoursParked
a public method called dailyCharges. It has no parameter and returns a String thatincludes a line by line summary of the time parked and the amounts charged (seeoutput)User a StringBuiler to create the output String
The class ParkingCharges should NOT include any print statements.
ad ParkingChargesTest
It includes jUnit tests to test the method
calculateCharges
Use equivalent partitions to find the boundary values.
Write a test case for each of the boundary values
Test that the expected exception is thrown if an invalid argument is passed
In class we discussed recommended best practices for jUnit testingI want you to pay special attention to two of these recommendations:
Choosing a descriptive name for each unit test
Striving to use one assertion per test case
ad ParkingChargesApp:
Ask the user to enter the hours parked for each customer.The user should be able to enter values like 1.5 or 6.75
Keep reading in data until the user enters -1.
If the value entered was invalid print a message that reminds the user of the valid range ofhours parked ( > 0 and <= 24 )
If the value entered was valid do the following:
1. display the charge for the current customer (see output)
2. add the hours parked to the list
display the daily charges
Output:
Hours parked (-1 to quit):0.5
Charge: $5.00
Hours parked (-1 to quit): 5.1
Charge: $11.00
Hours parked (-1 to quit): 7.1
Charge: $15.00
Hours parked (-1 to quit): 25
Hours parked need to be greater than 0 and less than or equal to 24.
Hours parked (-1 to quit): 13
Charge: $15.00
Hours parked (-1 to quit): -1
Daily Charges:
Hours parked: 0.50
charge: $5.00
Hours parked: 5.10
charge: $11.00
Hours parked: 7.10
charge: $15.00
Hours parked: 13.00
charge: $15.00
Explanation / Answer
import java.util.*;
import java.text.*;
class Parking {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("$##.##");
Scanner input = new Scanner(System.in);
double hr = 0.0;
int menu = 0;
System.out.println("Parking Charges");
System.out.println();
System.out.println("1. Two Wheeler");
System.out.println("2. Car");
System.out.println("3. Bus or Truck");
System.out.println("4. Exit");
boolean quit = false;
do {
System.out.print("Please enter your choice: ");
menu = input.nextInt();
System.out.println();
switch (menu) {
case 1:
System.out.print("Enter Number of hours 0 to 24: ");
hr = input.nextDouble();
System.out.println("**********Charges**********");
System.out.println("Vehicle type= Two Wheeler");
if (hr > 3) {
double amount = (hr - 3) * 1.50;
System.out.println("Charges= " + df.format(amount));
} else {
System.out.println("No charges");
}
break;
case 2:
System.out.print("Enter Number of hours: ");
hr = input.nextDouble();
System.out.println("**********Charges**********");
System.out.println("Vehicle type= Car");
if (hr > 2) {
double amount = (hr - 2) * 2.30 + 2.00;
System.out.println("Charges= " + df.format(amount));
} else {
double amount = (hr) * 1.00;
System.out.println("Charges= " + df.format(amount));
}
break;
case 3:
System.out.print("Enter Number of hours: ");
hr = input.nextDouble();
System.out.println("**********Charges**********");
System.out.println("Vehicle type= Bus/Truck");
if (hr > 1) {
double amount = (hr - 3) * 3.70 + 2.00;
System.out.println("Charges= " + df.format(amount));
} else {
double amount = (hr) * 2.00;
System.out.println("Charges= " + df.format(amount));
}
break;
case 4:
quit = true;
break;
default:
System.out.println("Hours parked need to be greater than 0 and less than or equal to 24");
}
}
while (!quit);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.