Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:

Best rate (male drivers, age 3365 and female drivers, age 30-62)--$40.00per day, $200.00 per week

Risk rate 1 (female drivers, age 2529)Best rate plus $10.00 per day or best rate plus $55.00 per week.

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

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 genderm 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:

oThe renters gender and age

oThe renters rate class

oThe renters rate per day and per week.

You may assume that user input provided will be valid for the base assignment (see Extra

Credit below.) Dates will be entered as individual integer values.

?Your program should be modular. Create separate methods for:

oCalculating age

oDetermining the rate class

oDisplaying 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.

Note: If you attempt the extra credit, 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.

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

T

his 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 p

er 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 enoug

h 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(

"

\

nSecond 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(

"

\

nThird test case: Renter is 35 and male (40/20

0)..."

);

birthMonth = 1;

birthDay = 1;

birthYear = 1981;

gender =

"m"

;

age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear);

rateResult = calcRateClass(age, gender);

displa

yResults(gender, age, rateResult);

System.out.println(

"

\

nFourth test case: Renter is 35 and female (40/200)..."

);

birthMonth = 1;

birthDay = 1;

birthYear = 1981;

gender =

"f"

;

age = calcAge(curMon

th, curDay, curYear, birthMonth, birthDay, birthYear);

rateResult = calcRateClass(age, gender);

displayResults(gender, age, rateResult);

System.out.println(

"

\

nFifth 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(

"

\

nSixth 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(

"

\

nSeventh 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, rateRe

sult);

System.out.println(

"

\

nEighth 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);

}

}

}

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

Question

What are the health and safety conditions?

Answered: 1 week ago

Question

deadlock

Answered: 1 week ago

Question

Analyse the various techniques of training and learning.

Answered: 1 week ago