Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tollcalculation 125% Zoom Insert Table ChartText Shape Media Comment Lab 4: Toll calculation Calculating toll based on time of day, day of week and carpool

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Tollcalculation 125% Zoom Insert Table ChartText Shape Media Comment 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 indexOfand substring methods. You will also need to use Integerparselnt(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 carpools, sometimes called high-occupancy vehicles (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: 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 (HHMM in 24 hour format): 17:15 Enter type of day (0- weekday, 1 - weekend/holiday):0 Enter number of persons in vehicle3 Toll at 17:15 pm is 0 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. 8 it Insert Format Arrange View Share Window Help Tollcalculation 125% Insert Table Chart Text Shape Media ViewZoom Add Page Time (am/pm) Time (24 hour) amount Before 6:00 am 00:00 to 5:59 1.55 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 ENTO unt oard ses 6:00 pm and after 18:00 to 00:00 1.55 ndar Method weekendCalculation: calculates the toll amount for travel on a weekend based upon 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. OX elp Toll Time (am/pm) Time (24 hour) Before 8:00 am 8:00 am to 11:59 am 8:00 to 11:59 3.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:59 3.60 7:00 pm to 9:59 pm 19:00 to 21:59 3.05 amount 00:00 to 7:59 1.55 t Format Arrange View Share Window Help Tollcalculation 125% v w Zoom Add Page Insert Table Chart Text Shape Media Comment 10:00 pm and after 22:00 to 00:00 1.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 n 24 hour format), 09:15 Enter type of day (0 -weekday1weekend/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 getlnput: returns input string from the user containing the time in hb.wm 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 parselnt0 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.parselntO which inputs a string and returns an int. 8 rt Format Arrange View Share Window Help Tollcalculation 125% iew Zoom Add Page Insert Table Chart Text Shape Media Requirements You would need to submit two files: TollCalculation java and TollMain java. TollMain java will contain a single call to calculate TollO. This method calls all other methods. All methods are defined in the file TollCalculation java. The hierarchy chart with method headers for the major methods in your assignment is given below double String getinput Scanner) double weekdayCalculation String ionstring carpoolcalculationscanne double weekDayCalculationString In addition to the above, the calculate Toll 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 /I before int hour Integer.parseInt (hourstring) return hour:) Format Arrange View Share Window Help Tollcalculation 125% v Zoom Add Page Insert Table Chart Text Shape Media Comment 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:MM in 24 hour format)::55 Enter type of day (Oo weekday, 1 - weekend/holiday): 0 Enter number of persons in vehicle: 1 Toll at 4 55 am is 1.55 Enter time of travel (HH:M in 24 hour format): 6:45 Enter type of day (0 weekday, 1- weekend/holiday): O Enter number of persons in vehicle:2 Toll at 645 am is 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 840 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): O Enter number of persons in vehicle: 1 Toll at 12 : 33 pm 2.35 Enter time of travel (HH:MM 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:MM in 24 hour format): Format Arrange View Share Window Help Tollcalculation 125% Zoom Add Page Insert Table Chart Text Shape Media Comment Enter time of travel (HH:MM in 24 hour format): 12:30 Enter type of day (o weekday, 1 - weekend/holiday) : 0 Enter number of persons in vehicle: 3 Toll at 1230 pm is 0.0 Enter time of travel (HH:M in 24 hour format): 8:45 Enter type of day (o weekday, 1 weekend/holiday): 0 Enter number of persons in vehicle: 3 Toll at 845 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 (o weekday, 1 - weekend/holiday): 1 Enter number of peraons in vehicle: 3 Toll at 23 45 pm is 0.0 Enter time of travel (HH:MM in 24 hour format): 11:20 Enter type of day (0 weekday, 1 - weekend/holiday): o Enter number of persons in vehicle: 3 Toll at 11 20 am is 0.0 0 5 Enter time of travel (HH:M in 24 hour format): 7:45 Enter type of day (O - weekday, 1 - weekend/holiday): 1 Enter number of persons in vehicle: 2 Toll at 7 45 am is 1.55 Enter time of travel (HH:MM in 24 hour format): 12:30 Enter type of day (o weekday, 1 - weekend/holiday): 1 Enter number of persons in vehicle: 2 Toll at 12 30 pm is 3.45 Enter time of travel (HH:MM in 24 hour format): 20:30 Enter type of day (0 weekday, 1 weekend/holiday): 1 Enter number of persons in vehicle: 2 Toll at 20: 30 pm is 3.05 Enter time of travel (HH:MM in 24 hour format): 7:35 Enter type of day ( weekday, 1 weekend/holiday): 1

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions