TapScanner 09-30-2021-20.54

You might also like

Download as pdf
Download as pdf
You are on page 1of 6
test motrin’ ry 2 Pe Ce ame eCe CR ects Pe) 24 Boe te oC ne a heer 25 a ee Cra a aoe Ceci Sree cn Pt) static final double SEDAN RATE = .€8 Et Bt Er re ae eee eee Cece oe ties Ey 34 Poste Ue Cie meee 35 36 Ed Cre a ee CeCe ott i 38 Er) Pete te Steen, ry 41 42 Co aor ae eCeC Rote Le 43 4 static final double VAN_RATE = .15; 45, 46 Cee ae ee CeCe ote iey Petes Cesar scm hea hee eed ee ee ee ee Ck err) Prot sCacC Rca cei one displayIntroduction(); ee rotenone en Ror OOH Tee eC SGN Ren aaa ee theVehicles[1] = new Sedan(SEDAN_RATE); NS tste ceo orm may} Rosettes meat) Tse) memo pets Reema crite asc mL Camco / create a Scanner for keyboard input Po eS Ce aur ety Cece ee eer ee ees String prompt = "\nEnter your cargo requirement (cubic feet) double cargo = promptForNonNegativellumber(console, prompt); prereeat er umcet Merci tes Rea double distance = promptForNonNegativeNunber(console, prompt Teo Umet eerste erent steer ee ECCS Ron ORG COA ee Cm ears Pres eyraeter eC Gr cc ervey as oT oOH 87 es 89 C oy Displays an introduction about the program 7 CereC Rey ier Mastin Gre eo ae ee or TGR aCe sstE tot my! n("The program then displays a list of vehicles eric > CR Cus emer ttre c a aa Cm Stars co ore Ce ty te ca i a ry ae cy ete ae Oe eC Ca cy Eres rt areea( prt) sie ae Tee a eerste pte PCr oar Uno etry oe Steer spe } peed Se ee pCa) prt pty Bary 119 cry cys pre cre cea srry i private static double getDouble(scanner console, String prompt) { System.out.print(prompt); eSpace ta erm SnSy area Pe cog eee eesti thos i} Feturn console.nextDouble()s oe ee eee Beste ester tong ‘String pronpt = "\nliould you Like to run the program again? (Y/N): “s ees eras ane eno eee ee eee Pace gees peer ena eSr Span oear eed public static boolean getVer0rtio(String prompt) { ‘Scanner console = new Scanner (5; eee es String response = consolle.nextLin. while (1(response.equalstgnorecase("Y") |] response.equalstgnoreCase("N") Hae aca eect yar Pen eect anes tr ott aoe cies ee eo esponse = console.nextLine(); N return (response.equalsTgnorecase("Y") || response-equalsignorecase(*YES")); ) ee eee ree Rue Pr errr ern ren rr oc ead aie public static void outputResults(double cargo, double Poemeneeerte tat ates tn Os a PosPenennes notre irs) for (int index = 0; index < thevehicles.length; indext+) { Farcntnre tees reer CT eens ond peremperemertr icon troy PS erreree Praca ree ens ne naro ne Sneuronce = ((abstractTruck) theVehicles[index]).getInsuranceCost(distance, cargo); een Insurance = ((AbstractCar) theVehicles[index]).getinsuranceCost (distance); y PS a et en eer erences coat ey double total = insurance + mileagecharges porn eet Gt OC ac ey D i era Perris etme ee OCeT LOC i plays an exit message public static void displayexitnessage() ( Pennant eee mentee Co oe eC One Sater os oT eee Peed Wag super (the @verride Cae Sed if (t Ace ee v7 ea a oe enn cay aOR for using the Vehicle Rental program. Have a nice day.”); ease! n(double Ce i Puy eta at std ; t(double theDistance) { Ra eertastts Se TOF } De mS ets FP ECC es cE ty EXPECTED OUTPUT: The vehicle rental agency has an interactive program that prompts for an amount of cargo and a distance and then produces a list of suitable vehicles and the total rental cost for each. Below is shown ‘output from the program. This program is provided in the starter code (VehicleRental java). You can use the program to test your Vehicle classes. ‘This program prompts the user to enter a cargo requirement and a trip distance. ‘The program then displays a list of vehicles suitable for the requirements. Rnter your cargo requirement (cubic feet) : 2.5 Enter trip distance (miles) : 270 ‘Your choices are: Type Capacity Insurance Total Sportscar 5.0 cu. ft. $20.25 987.75 Sedan 35.0 cu. ft. $5. $27.00 Stationmagon 60.0 cu. ft. $2.70 $29.70 Pickup 100.0 cu. #t. $0.68 $33.07 van 200.0 cu. ft. 68 941.18 MovingTruck 600.0 cu. ft. $0.68 $54.68 Would you like to run the program again? (¥/M): y Enter your cargo requirement (cubic feet) : 180 Enter trip distance (miles) : 5000 ‘Your choices are: Type Capacity Rate van 200.0 cu. ft. $0.15 / mi Moving?ruck 600.0 cu. ft. $0.20 / mi Would you like te run the program again? (1/M): yes Enter your cargo requirement (cubic feet) : ten Mot a number; try again. Rater your cargo requirement (cubic feet) : 10 mnter trip distance (miles) : -10 ‘The number must be non-negative; please try again. nter trip distance (miles) : 1000 Rate Insurance ‘Total ft. $0.08 / mi $20.00 $100.00 ft. $0.10 / mi $10.00 $110.00 ft. $0.12 / mi $10.00 $130.00 ft. $0.15 / mi $10.00 $160.00 ft. $0.20 / mi $10.00 $210.00 Would you like to run the program again? (¥/m): maybe Invalid input. Please try again. Would you like to run the program again? (¥/M): no ‘Thanks for using the Vehicle Rental program. Have a nice day.

You might also like