Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Create a class named CarRental that contains fields that hold a renter’s name

ID: 3636244 • Letter: A

Question

a. Create a class named CarRental that contains fields that hold a renter’s name, zip code, size of the car rented, daily rental fee, length of rental in days, and total rental fee. The class contains a constructor that requires all the rental data except the daily rate and total fee, which are calculated, based on the size of the car: economy at $29.99 per day, midsize at $38.99 per day, or full size at $43.50 per day. The class also includes a display() method that displays all the rental data.

b. Create a subclass named LuxuryCarRental. This class sets the rental fee at $79.99 per day and prompts the user to respond to the option of including a chauffeur at $200 more per day. Override the parent class display() method to include chauffeur fee information.

c. 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 total rental fee.

Explanation / Answer

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Name of person:");
String name = scan.nextLine();

System.out.println("Zipcode:");
int zip = scan.nextInt();

System.out.println("Size of car:(1=economy,2=mid,3=full,4=luxury)");
int size = scan.nextInt();

System.out.println("Days of rental:");
int days = scan.nextInt();

if(size!=4)
{
CarRental cr = new CarRental(name, zip, size, days);
cr.Display();
}
else
{
System.out.print("Do you want a chauffeur? (y/n) ");
scan.nextLine();
char c = scan.nextLine().charAt(0);
boolean chauf = (c=='y') ? true : false;
System.out.println();

LuxuryCarRental lcr = new LuxuryCarRental(name, zip, days, chauf);
lcr.Display();
}
}
}

import java.text.*;
public class CarRental
{
public final int ECONOMY = 1, MIDSIZE = 2, FULL = 3;
private int size, zip, time;
private float fee, total_fee;
private String name;
private DecimalFormat df;

private CarRental(){}

public CarRental(String name, int zip, int size, int time)
{
df = new DecimalFormat("$#.##");
this.name = name;
this.size = size;
this.zip = zip;
this.time = time;
switch(size)
{
case ECONOMY: fee = 29.99f; break;
case MIDSIZE: fee = 38.99f; break;
case FULL: fee = 43.5f; break;
default:break;
}

total_fee = fee * time;
}

public void Display()
{
System.out.println("Name: " + name);
System.out.println("Zipcode: " + zip);
System.out.println("Days to rent: " + time);

switch(size)
{
case ECONOMY: System.out.println("Size of car: economy."); break;
case MIDSIZE: System.out.println("Size of car: midsize."); break;
case FULL: System.out.println("Size of car: full."); break;
default: break;
}

System.out.println("Fee of car: " + df.format(fee));
System.out.println("Total Fee: " + df.format(total_fee));
}

//::Get info below.
public int getSize()
{
return size;
}
public int getDays()
{
return time;
}
public float getFee()
{
return fee;
}
public float getTotalFee()
{
return total_fee;
}
public int getZip()
{
return zip;
}
}


import java.text.*;
public class LuxuryCarRental extends CarRental
{
private boolean chauffeur;

public LuxuryCarRental(String name, int zip, int time, boolean chauffeur)
{
super();
this.chauffeur = chauffeur;
super.df = new DecimalFormat("$#.##");
super.name = name;
super.zip = zip;
super.time = time;
super.size = -1;

super.fee = 79.99f;
super.total_fee = super.fee * super.time;

if(chauffeur)
super.total_fee += 200.0f;
}

@Override
public void Display()
{
super.Display();
System.out.println("Car Type: Luxury.");

if(chauffeur)
System.out.println("You asked for a chauffeur.");
else
System.out.println("You declined a chauffeur.");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote