Create a class named CarRental that contains fields that hol
Create a class named CarRental that contains fields that hold a renter\'s name, zip code, size of the car rented, daily rental rate, length of rental (in days), and total cost. The class contains a constructor that requires all the rental data user information (name, zip, size, length). The daily rental rate depends on the size of the car:
economy: $29.99 per day
midsize: $38.99 per day
fullsize: $43.50 per day
Calculate the total cost for the rental car and include a display( ) method to display all the rental information.
Create a subclass named LuxuryCarRental. This class sets the daily rental rate to $79.99 per day and prompts the user to respond to the option of including a chauffeur at and additional $200 per day. Override the parent class display( ) method to include the chauffeur fee information.
Write an application named UseCarRental that prompts the user for the data needed for a rental and creates an object of the correct type. Display the rental information with the total cost for the car.
Save the files as CarRental.java, LuxuryCarRental.java, UseCarRental.java
Solution
i am copying the code, create those files and paste the content
CarRental.java
public class CarRental {
static String RenterName = null;
static String ZipCode = null;
static String Size = null;
static int Length = 0;
static double TotalCost = 0.0f;
CarRental(String rentername, String zipcode, String size, int length )
{
RenterName = rentername;
ZipCode = zipcode;
Size = size;
Length = length;
if(Size.equalsIgnoreCase(\"economy\"))
{
TotalCost = 29.99*Length;
}
else if(Size.equalsIgnoreCase(\"midsize\"))
{
TotalCost = 38.99*Length;
}
else
{
TotalCost = 43.50*Length;
}
display();
}
static void display()
{
System.out.println(\"RenterName\\t\"+RenterName);
System.out.println(\"ZipCode\\t\"+ZipCode);
System.out.println(\"Size\\t\"+Size);
System.out.println(\"Length\\t\"+Length);
System.out.println(\"TotalCost $\\t\"+TotalCost);
}
}
LuxuryCarRental.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class LuxuryCarRental {
static String RenterName = null;
static String ZipCode = null;
static String Size = null;
static int Length = 0;
static double TotalCost = 0.0f;
LuxuryCarRental(String rentername, String zipcode, String size, int length )
{
RenterName = rentername;
ZipCode = zipcode;
Size = size;
Length = length;
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(System.in));
boolean userinp = true;
while(userinp)
{
System.out.println(\"do you want chauffeur at and additional $200 per day:type - yes or no\");
String userdesc = br.readLine();
if(userdesc.equalsIgnoreCase(\"no\"))
{
userinp = false;
TotalCost = 79.99*Length;
}
else if(userdesc.equalsIgnoreCase(\"yes\"))
{
userinp = false;
TotalCost = 279.99*Length;
}
else
{
userinp = true;
System.out.print(\"invalid input\");
}
display();
}
} catch (Exception e) {
e.printStackTrace();
}
}
static void display()
{
System.out.println(\"RenterName\\t\"+RenterName);
System.out.println(\"ZipCode\\t\"+ZipCode);
System.out.println(\"Size\\t\"+Size);
System.out.println(\"Length\\t\"+Length);
System.out.println(\"TotalCost $\\t\"+TotalCost);
}
}
UseCarRental.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class UseCarRental {
public static void main(String[] args)
{
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(\"enter user name\");
String uname = br.readLine();
System.out.println(\"enter zip code\");
String zip = br.readLine();
boolean userinp = true;
String size = null;
while(userinp)
{
System.out.println(\"select car size - economy, midsize, fullsize, luxury \");
size = br.readLine();
if(size.equalsIgnoreCase(\"economy\")
||size.equalsIgnoreCase(\"midsize\")
||size.equalsIgnoreCase(\"fullsize\")
||size.equalsIgnoreCase(\"luxury\"))
{
userinp = false;
}
else
{
System.out.println(\"invalid input\");
userinp = true;
}
}
System.out.print(\"enter num of days\");
int days = Integer.parseInt(br.readLine());
if(size.equalsIgnoreCase(\"economy\")
||size.equalsIgnoreCase(\"midsize\")
||size.equalsIgnoreCase(\"fullsize\"))
{
CarRental tempCarRental = new CarRental(uname,zip,size,days);
}
else
{
LuxuryCarRental tempLuxuryCarRental = new LuxuryCarRental(uname,zip,size,days);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}




