Write a program called RentalRate.java which reads in
a date of birth, today’s 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 33–65 and female drivers, age 30-62)--$40.00per day, $200.00 per week
Risk rate 1 (female drivers, age 25–29)–Best rate plus $10.00 per day or best rate plus $55.00 per week.
Risk rate 2 (male drivers, age 25–32)–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 renter’s gender–m or f.
?If not attempting extra credit, ask the user for today’s date
?Then ask the user for the renter’s month, day and year of birth (also see extra credit.)
?The program will determine the renter’s age and display:
oThe renter’s gender and age
oThe renter’s rate class
oThe renter’s 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 renter’s gender (m/f):
m
Please enter today's date (mm dd yyyy):
10 4 2011
Please enter the renter’s 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 today’s date, and invalid data will cause an error message to be displayed.
Note: The ‘Date’ class has been replaced with a more capable utility–the ‘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);
}
}
}
Given below is the code for the question. The extra credit part is done. Also you can change the DEBUG = true to test the various test cases. If DEBUG = false, then it will prompt for data from user. It will not prompt for current date since extra credit part is implemented and the program gets the current date from Calendar.
To indent code in eclipse , select code by pressing ctrl+a and
then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
// 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("\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/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("\nFourth test case: Renter is 35 and female
(40/200)...");
birthMonth = 1;
// //
// //
//If you're not attempting the EC, get today's date from the user... Your code goes here...
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("\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, rateResult);
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 are attempting the
//Your code goes here...
//EC, use the Calendar class to get today's date...
Calendar cal = Calendar.getInstance();
curDay = cal.get(Calendar.DAY_OF_MONTH);
curMonth = cal.get(Calendar.MONTH);
curYear = cal.get(Calendar.YEAR);
// Get the gender...
System.out.print("Please enter the renter’s gender (m/f):
");
gender = kb.next();
// Get the date of birth...
System.out.print("Please enter the renter’s date of birth (mm dd
yyyy): ");
birthMonth = kb.nextInt();
birthDay = kb.nextInt();
birthYear = kb.nextInt();
// 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); }
}
private static void displayResults(String gender, int age,
String rateResult) {
String s = "";
if(gender.equalsIgnoreCase("m"))
s = "male";
else
s = "female";
System.out.printf("The %s renter is %d years old.\n", s,
age);
System.out.println("The rate class is: " + rateResult);
}
private static String calcRateClass(int age, String gender)
{
if(age < 25)
return "Sorry, the renter is not 25 years of age or older.";
if(gender.equalsIgnoreCase("m"))
{
if(age <= 32)
return RISK_RATE_2;
else if(age <= 65)
return BEST_RATE;
else
return RISK_RATE_3;
}
else
{
if(age <= 29)
return RISK_RATE_1;
else if(age <= 62)
return BEST_RATE;
else
return RISK_RATE_3;
}
}
private static int calcAge(int curMonth, int curDay, int
curYear, int birthMonth, int birthDay, int birthYear) {
int age = curYear - birthYear;
//check for conditions when the birthday for the current year is
not yet over
if(birthMonth > curMonth)
age = age-1;
else if(birthMonth == curMonth && birthDay >
curDay)
age = age - 1;
return age;
}
}
output( DEBUG = false)
--------------------------
Welcome to the car renter's rate finder.
Please enter the renter’s gender (m/f): m
Please enter the renter’s date of birth (mm dd yyyy): 10 4
2011
The male renter is 6 years old.
The rate class is: Sorry, the renter is not 25 years of age or
older.
output( DEBUG = true)
-------------
First test case: Renter is not old enough to rent...
The male renter is 24 years old.
The rate class is: Sorry, the renter is not 25 years of age or
older.
Second test case: Renter is barely old enough (57/285)...
The male renter is 25 years old.
The rate class is: Risk rate 2-$57.00 per day or $285.00 per
week.
Third test case: Renter is 35 and male (40/200)...
The male renter is 35 years old.
The rate class is: Best rate - $40.00 per day or $200.00 per
week.
Fourth test case: Renter is 35 and female (40/200)...
The female renter is 35 years old.
The rate class is: Best rate - $40.00 per day or $200.00 per
week.
Fifth test case: Renter is 30 and male (57/285)...
The male renter is 30 years old.
The rate class is: Risk rate 2-$57.00 per day or $285.00 per
week.
Sixth test case: Renter is 30 and female (40/200)...
The female renter is 30 years old.
The rate class is: Best rate - $40.00 per day or $200.00 per
week.
Seventh test case: Renter is 76 and male (62/255)...
The male renter is 76 years old.
The rate class is: Risk rate 3-$%4.2f per day or $%5.2f per
week.
Eighth test case: Renter is 76 and female (68/270)...
The female renter is 76 years old.
The rate class is: Risk rate 3-$%4.2f per day or $%5.2f per
week
Write a program called RentalRate.java which reads in a date of birth, today’s date and a...
Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models a person */ public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) {...
Extend this date validation program, so that it checks for valid leap years (in which the month February has 29, instead of 28, days). A leap year is any year that is divisible by 4 but not divisible by 100, unless it is also divisible by 400. Do not allow February to have 29 days on years that are not leap years. **Please view both photos for the entire code and post new code with the leap year modification. Thank...
I need to create a Java class file and a client file that does the following: Ask user to enter Today’s date in the form (month day year): 2 28 2018 Ask user to enter Birthday in the form (month day year): 11 30 1990 Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...
Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...
The body mass index (BMI) is a measure of relative weight based on height and weight. The body fat percentage (BFP) of a human or other living being is the total mass of fat divided by total body mass, multiplied by 100; body fat includes essential body fat and storage body fat. Essential body fat is necessary to maintain life and reproductive functions. Write a program that calculates and prints the BFP for multiple persons; the program allows user to...
Write a program named CheckMonth2 that prompts a user to enter a birth month and day. Display an error message that says Invalid date if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message. For example, if the month entered is 2, and the day...
I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...