Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help for this homework in Java language: Homework: Write a program called RentalRate.java which reads in a date of birth, todays date

Hello, I need help for this homework in Java language:

Homework:

Write a program called RentalRate.java which reads in a date of birth, todays date and a male/female designation from the user, and will then determine the basic daily and weekly rates for rental of an economy class car.

Rental rate classes are:

o Best rate (male drivers, age 33 65 and

female drivers, age 30 - 62) -- $40.00

per day, $200.00 per week

o Risk rate 1 (female drivers, age 25 29)

Best rate plus $10.00 per day or best rate plus $55.00 per week.

o Risk rate 2 (male drivers, age 25 32) Risk rate 1 plus $7.00 per day or risk rate 1 plus $30.00 per week.

o Risk rate 3 (male driver, age 66+ and female drivers, age 63+) Best rate plus $2.00 for each year over age 65 (male) or 62 (female), per day or best rate plus $5.00 for each year over age 65 (male) or 62 (female), per week.

PROGRAM PARTICULARS:

_When the program starts, ask the user for the renters gender m or f.

_If not attempting extra credit, ask the user for todays date

_Then ask the user for the renters month, day and year of birth (also see extra credit.)

_The program will determine the renters age and display:

o The renters gender and age

o The renters rate class

o The renters rate per day and per week.

You may assume that user input provided will be valid for the base assignment. Dates will be entered as individual integer values.

_Your program should be modular. Create separate methods for:

o Calculating age

o Determining the rate class

o Displaying the results.

EXAMPLE RUN:

Welcome to the car renter's rate finder.

Please enter the renters gender (m/f): m

Please enter today's date (mm dd yyyy): 10 4 2011

Please enter the renters date of birth (mm dd yyyy): 1 22 1990

Thank you.

The male renter is 21 years old.

The rate class is: Sorry, the renter is not 25 years of age or older.

Welcome to the car renter's rate finder.

Please enter the renters gender (m/f): f

Please enter today's data (mm dd yyyy): 10 4 2011

Please enter the renters date of birth (mm dd yyyy): 11 1 1980 Thank you.

The female renter is 30 years old. The rate class is: Best rate - $40.00 per day or $200.00 per week.

Your sample run will differ from the above listing as you will not need to ask for todays date, and invalid data will cause an error message to be displayed.

HINTS:

_Be sure to test for borderline cases.

Note: The Date class has been replaced with a more capable utility the Calendar class. Use the Calendar class instead.

You must figure out how to use this Java library API yourself.

Special Note: This assignment will provide you with a pre-written main() method. You must make your code conform to the pre-written main method:

// Rental rates assignment // Pre-set main for testing (see DEBUG constant) // Required methods to be added: calcAge(...), calcRateClass(...) and displayResult(...) // Also, insert code into main as indicated. import java.util.*; public class RentalRates { private static final boolean DEBUG = true; private static final String BEST_RATE = "Best rate - $40.00 per day or $200.00 per week."; private static final String RISK_RATE_1= "Risk rate 1-$50.00 per day or $255.00 per week."; private static final String RISK_RATE_2= "Risk rate 2-$57.00 per day or $285.00 per week."; private static final String RISK_RATE_3= "Risk rate 3-$%4.2f per day or $%5.2f per week."; public static void main(String[] args) { int curMonth = 0; int curDay = 0; int curYear = 0; int birthMonth = 0; int birthDay = 0; int birthYear = 0; String gender = ""; int age = 0; String rateResult; // Testing mode... if (DEBUG == true) { // Establish a 'current' date for testing... curMonth = 2; curDay = 1; curYear = 2016; System.out.println("First test case: Renter is not old enough to rent..."); birthMonth = 2; birthDay = 2; birthYear = 1991; gender = "m"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Second test case: Renter is barely old enough (57/285)..."); birthMonth = 2; birthDay = 1; birthYear = 1991; gender = "m"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Third test case: Renter is 35 and male (40/200)..."); birthMonth = 1; birthDay = 1; birthYear = 1981; gender = "m"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Fourth test case: Renter is 35 and female (40/200)..."); birthMonth = 1; birthDay = 1; birthYear = 1981; gender = "f"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Fifth test case: Renter is 30 and male (57/285)..."); birthMonth = 1; birthDay = 1; birthYear = 1986; gender = "m"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Sixth test case: Renter is 30 and female (40/200)..."); birthMonth = 1; birthDay = 1; birthYear = 1986; gender = "f"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Seventh test case: Renter is 76 and male (62/255)..."); birthMonth = 1; birthDay = 1; birthYear = 1940; gender = "m"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); System.out.println(" Eighth test case: Renter is 76 and female (68/270)..."); birthMonth = 1; birthDay = 1; birthYear = 1940; gender = "f"; age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); rateResult = calcRateClass(age, gender); displayResults(gender, age, rateResult); } else { Scanner kb = new Scanner(System.in); System.out.println("Welcome to the car renter's rate finder."); // If you're not attempting the EC, get today's date from the user... // Your code goes here... // If you are attempting the EC, use the Calendar class to get today's date... // Your code goes here... // Get the gender... // Your code goes here... // Get the date of birth... // Your code goes here... // Get age... age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear); // Get the rental rate... rateResult = calcRateClass(age, gender); // Display the results... displayResults(gender, age, rateResult); } } }

Thank you.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions