Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 4: Toll calculation Calculating toll based on time of day, day of week and carpool status Write a program that calculates the toll amount

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Lab 4: Toll calculation Calculating toll based on time of day, day of week and carpool status Write a program that calculates the toll amount for travel along a toll road or toll lane. The toll amount is based on the time of day, day of the week, and number of persons in the vehicle The program gets the time of travel from the user using 24 hours format as a string, then extracts the hour to determine the toll amount. You will need indexOf and substring methods. You will also need to use Integer.parselnt(inputString) method to convert a string to integer The program also asks for type of day from the user (0 for weekdays, and 1 for weekends or holidays) Since a toll road may have a discount for (HOV). The program asks for the number of people in the vehicle to adjust the toll amount based on this information. The carpool discount rules are carpools, sometimes called high-occupancy vehicles A carpool is 3 or more person per vehicle The toll for carpools on weekdays between 6:00 am and 10:00 am is half the normal toll Otherwise, the toll for carpools is 0 (as in free) Use if-else, nested if-else and multi-branch if-else statement as needed to determine the tollAmount based on the tables and user information. Sample output . Enter time of travel (HH : MM in 24 hour format): 17:15 Enter type of day (0-weekday, 1-weekend/holiday): 0 Enter number of persons in vehicle:3 Toll at 1:15 pm is The primary modules that you will write are Method weekdayCalculation: calculates the toll amount for travel on a weekday based upon the toll schedule below. The table lists times in both am/pm format and 24-hour format. Weekday toll schedule Time (am/pm) Time (24 hour) Toll amount Before 6:00 am 6:00 am to 9:59 am 6:00 to 9:59 4.65 10:00 am to 5:59 pm 10:00 to 17:59 2.35 00:00 to 5:591.55 6:00 pm and after 18:00 to 00:001.55 Method weekendCalculation: calculates the toll amount for travel on a weekend based upor the toll schedule below. The table lists times in both am/pm format and 24-hour format. Calculating toll based on time of day and day of week A toll road often has a different toll schedule for weekends and holidays than for weekdays. The table below lists the toll schedule for weekends and holidays. Toll schedule for weekends and holidays Time (am/pm) Time (24 hour) Toll amount Before 8:00 am 8:00 am to 11:59 am 8:00 to 11:593.05 12:00 pm to 3:59 pm 12:00 to 15:59 3.45 4:00 pm to 6:59 pm 16:00 to 18:593.60 7:00 pm to 9:59 pm19:00 to 21:59 3.05 10:00 pm and after 22:00 to 00:00 1.55 00:00 to 7:591.55 Calculating toll with carpool discount Method carpoolCalculation: calculates the toll amount based on carpool discount rules are A carpool is 3 or more person per vehicle The toll for carpools on weekdays between 6:00 am and 10:00 am is half the normal toll Otherwise, the toll for carpools is 0 (as in free) . Enter time of travel (HH: MM in 24 hour format): 09:15 Enter type of day (0-weekday, 1-weekend/holiday): 0 Enter number of persons in vehicle:3 Toll at 09:15 pm is 2.325 Getting user iput and extracting integers from string (string processing) Method getInput: returns input string from the user containing the time in hh:mm format. Method getHours: uses string methods indexOf and substring to extract the hours before the colon. It converts hours in string to hours in integer using Integer.parselnt(0 which inputs a string and returns an int Method getMinutes: uses string methods indexOf and substring to extract the hours after the colon. It converts minutes in string to minutes in integer using Integer.parselnt0 which inputs a string and returns an int. Requirements You would need to submit two files: TollCalculation.java and TollMain java TollMain.java will contain a loop that makes 10 calls to TollCalculationcalculateTollO. This method calls all other methods. All other methods are defined in the file TollCalculation java and may be labeled as private. The hierarchy chart with method headers for the major methods in your assignment is given below. TollCalculation.calculateToll) double weekendCalculation(String) double double weekdayCalculation(String) String getlnput(Scanner) carpoolCalculation(Scanner) double In addition to the above, the calculateToll method calls two methods for parsing the input string to extract the hours and minutes: A shell of one sample method is given below: public static int getHour (String time) String hourString - //use substring method and indexOf method to extract hour // before: int hour-Integer.parseInt(hourString) return hour;) Additional small helper methods to get typeofDay and numberOfPersons may also be defined Output testing Here are the tests that your program needs to pass: The input must be entered as HH:MM. No input validation to is to be done Enter time of travel (HH:M in 24 hour format): 4:55 Enter type of day (0 -weekday, 1-eekend/holiday): 0 Enter number of persons in vehicle: 1 Toll at 4:55 am is 1.55 Enter time of travel (HH:MM in 24 hour format): 6:45 Enter type of day (0 weekday, 1 weekend/holiday): 0 Enter number of persons in vehicle: 2 Toll at 6 : 45 am i3 4.65 Enter time of travel (HH:MM in 24 hour format): 8:40 Enter type of day (0 weekday, 1 - weekend/holiday): 0 Enter number of persons in vehicle: 1 Toll at 8:40 am is 4.65 Enter time of travel (HH:MM in 24 hour format) 12:33 Enter type of day (0 weekday, 1 weekend/holiday):0 Enter number of persons in vehicle: 1 Toll at 12 33 pm is 2.35 Enter time of travel (HH:M in 24 hour format): 20:00 Enter type of day (0 weekday, 1- weekend/holiday):0 Enter number of persons in vehicle: 2 Toll at 20:0 pm is 1.55 Enter time of travel (HH:M in 24 hour format) Enter time of travel (HH:MM in 24 hour format): 12:30 Enter type of day (0 weekday, 1 weekend/holiday) : 0 En ter number of persons Toll at 12 : 30 Enter time of travel (HH:MM in 24 hour format): 8:45 Enter type of day (0 weekday, 1 weekend/holiday): 0 En pm is 0.0 ter number of persons in Toll at 8 : 45 am is 2.325 Enter time of travel (HH:MM in 24 hour format): 10:30 Enter type of day (0 weekday, 1 - weekend/holiday): 1 Enter number of persons in vehicle: 3 Toll at 10: 30 am is 0.0 Enter time of travel (HH:MM in 24 hour format) 23:45 Enter type of day (0 -weekday, 1-weekend/holiday) 1 En number of persons in ter Toll at 23: 45 pm is 0.0 Enter time of travel (HH:M in 24 hour format) 11:20 Enter type of day (0- weekday, 1- weekend/holiday) 0 Enter number persons 1n vehicle Toll at 11 20 am is 0.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions