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

Problem Description: You are to develop a Java program capable of maintaining ve

ID: 672492 • Letter: P

Question

Problem Description:
You are to develop a Java program capable of maintaining vehicle rental reservations for a given vehicle rental agency using an object-oriented design.

Problem Scenario:
The vehicle rental agency has only corporate customers. That is, the agency rents vehicles to client companies on an ongoing basis that need to rent vehicles for business use. The agency offers cars, SUVs and moving trucks for rent. Vehicles may be rented for a period of days, weeks, or months. Monthly rentals are cheaper (on a daily basis) than weekly rentals, and weekly rentals are cheaper than daily rentals. Cars, SUVs and trucks each have their own rental rates. There is no difference in the rate among various models of cars, SUVs or trucks. Company clients may do the following: (1) view the current rental rates for all vehicle types, (2) view a list of all available (unreserved) vehicles, (3) display the cost of a particular rental (for a given vehicle type, the rental period, expected number of miles driven, and insurance option), (4) reserve a vehicle, (5) cancel a reservation, and (6) display an itemized list of the total rental cost for all currently reserved vehicles of a given company. Vehicles are identified in the system based on their VIN (Vehicle Identification Number), which is unique for all other vehicles. The set of features for cars, SUVs and trucks are different. Cars are specified as a particular make and model, the number of miles per gallon that it is capable of, and the number of seats. SUVs are specified as a particular make and model, the number of miles per gallon, and the number of bench seats. Trucks are specified as a particular length, miles per gallon, and number of rooms storage capacity.

Make/Model Mileage Num VIN Seats CARS

Chevrolet Camaro 30 mpg 2 WG8JM5492DY
Chevrolet Camaro 30 mpg 2 KH4GM4564GD
Ford Fusion 34 mpg 4 AB4FG5689GM
Ford Fusion Hybrid 35 mpg 4 GH2KL4278TK
Ford Fusion Hybrid 32 mpg 4 KU4EG3245RW
Chevrolet Impala 36 mpg 4 QD4PK7394Jl
Chevrolet Impala 30 mpg 4 RK3BM4256YH

Make/Model Mileage Num VIN Bench Seats SUVs

Chrysler Town&Country 25 mpg 3 DK3KG8312UE
Chrysler Town&Country 25 mpg 3 VM9RE2645TD
Chrysler Town&Country 25 mpg 3 WK8BF4287DX
Dodge Caravan 25 mpg 2 QK3FL4278ME
Dodge Caravan 25 mpg 2 KY8EW2053XT
Ford Expedition 20 mpg 2 JK2RT8364HY
Ford Expedition 20 mpg 2 KH4ME4216XW

Make/Model Mileage Num Rooms VIN Capacity Trucks
Ten-Foot 12 mpg 1 bedroom EJ5KU2435BC
Ten-Foot 12 mpg 1 bedroom KF8JP7293EK
Seventeen-Foot 10 mpg 2 bedrooms KG4DM5472RK
Seventeen-Foot 10 mpg 2 bedrooms PR8JH4893WQ
Twenty-Four-Foot 8 mpg 4 bedrooms EP2WR3182QB
Twenty-Four-Foot 8 mpg 4 bedrooms TY3GH4290EK
Twenty-Four-Foot 8 mpg 4 bedrooms KU9FL4235RH

Program Requirements:

The program must be able to maintain a group of specific model vehicles for the following vehicle categories: cars, SUVs, and trucks.

The program must be able to maintain the following characteristics for each type of vehicle: Cars: make/model, miles per gallon, num of seats, vehicle number (VIN) SUVs: make/model, miles per gallon, num of bench seats, vehicle number (VIN) Trucks: length, miles per gallon, num of rooms capacity, vehicle number (VIN)

The display of available vehicles must include (for each specific vehicle): a description (make/model or length for trucks), mpg, num doors/bench seats/rooms of storage and VIN, in the following format:
Description: Ford Fusion MPG: 34 Num Seats: 4 VIN: AB4FG5689GM
Description: Dodge Caravan MPG: 25 Num Bench Seats: 2 VIN: QK3FL4278ME
Description: Ten-Foot Truck MPG: 12 Num Rooms Capacity: 1 VIN: EJ5KU2435BC

The program must allow for a specific vehicle to be reserved for a given number of days, weeks, or months. The user must enter the VIN of the vehicle to reserve. They will then be prompted to enter the company name, credit card number, rental period (days, weeks, or months), and if they want the daily insurance or not. (Note that in our scenario, a company will rent a number of vehicles at any given time.)

The program must allow for reservations to be cancelled.

The program must be able to provide the user an estimated cost of a rental including the estimated number of miles driven (to account for the per/mile charge) besides the vehicle type, rental period, and insurance option.

The program must allow a company to get a list of the base cost (without the per mile charge) of each of its currently reserved vehicles invidually, as well as the total cost.

The program displays the following main menu:
<<< MAIN MENU >>>
1 - Display rental rates
2 - Display available vehicles
3 – Display a specific rental cost
4 – Make a reservation
5 - Cancel a reservation
6 – Display company reservations
7 - Quit

Option 1 – displays the daily, weekly and monthly rental rates for a specific vehicle type (car, suv, truck)
Option 2 – displays a list of available vehicles, including description (make/model, truck length), mpg, num doors/bench seats/rooms of storage, and VIN.
Option 3 – displays the cost of a rental for a specific vehicle, rental period (number of days, weeks or months), estimated number of miles driven, insurance option (yes/no).
Option 4 – allows a user to make a reservation for a provided VIN, providing a company name and credit card number.
Option 5 – allows a user to cancel a reservation for a provided VIN.
Option 6 – allows a user to display all the vehicles currently reserved for a given company, and the total base cost (excluding mileage charge) for each, and the total (base) cost

Rental Rates:
Following is an example of rental rates that you may use (to be hard-coded in the program):

Car (Daily)$24.95 (Weekly)$149.95 (Monthly)$514.95
SUV (Daily)$29.95 (Weekly)$189.95 (Monthly)$679.95
Truck (Daily)$34.95 (Weekly)$224.95 (Monthly)$797.95

Per Mile Charge (same for all vehicles) 0.15 / mile

Insurance Rate (same for all vehicles) $14.95 / day

Classes Needed:

Abstract Vehicle Class (contains only one abstract method)

instance variables:
String description // make-model for cars/suvs, length for trucks
String mpg
String num // represents something different in each class (e.g., num seats, num bench seats, etc.)
String VIN
Reservation resv // if assigned to a Reservation object. If null, then vehicle is not currently reserved

methods:
(appropriate constructor)
getDescription() // ABSTRACT METHOD – implemented in each subclass // returns a string containing the information about a particular vehicle, // as shown at the bottom of page 2 above
isReserved() // returns true if reserved
reserve(reservation info)
cancelReservation() // sets reference to Reservation object to null
getVIN() // returns vehicle identification number
getReservation() // returns reference to associated reservation object

Reservation Class:
   instance variables
   String companyName
   String creditCardNum
   String rentalPEriodType // days, weeks, months
   String rentalTime // 1,2,3, ... (can convert to int when needed)

methods
   (appropriate constructor)
   getCompanyName()
getCreditCardNum()
   getRentalPeriodType()
   getRentalTime()
   toString() // returns a string containing company name, credit card number used, and rental
// period/rental time
** Note that reservations cannot be altered once created. Thus, there are no setters in the Reservation class.   

Main Class

Creates array of Vehicle objects, initialized for the vehicles of the rental agency
Contains the rental rates for all vehicle types
Provides the main menu of user options

Exception Handling:
You must use exception handling for the following situations:
Non-existing VIN given when reserving a vehicle (VINNotFoundException)
Invalid credit card number entered (assume must be 10 digits) (InvalidCreditCardException)
Company not found when requesting list of reserved vehicles (CompanyNotFoundException)

Explanation / Answer

vechile2 class:

package vehicle2;
public abstract class Vehicle2
{
int Vin, MilePG;
String Make, Model;
Reservation reserve;
double DailyCost, WeeklyCost, MonthlyCost;
public Vehicle2(int MPG, String mke, String mdl)
{
Make = mke;
Model = mdl;
MilePG = MPG;
reserve = null;
}
public int getVin()
{
return Vin;
}
public int getMilePG()
{
return MilePG;
}
public String getMake()
{
return Make;
}
public String getModel()
{
return Model;
}
public double getDailyCost()
{
return DailyCost;
}
public double getWeeklyCost()
{
return WeeklyCost;
}
public double getMonthlyCost()
{
return MonthlyCost;
}
public void setVin(int vn)
{
Vin = vn;
}
public void setMilePG(int MPG)
{
MilePG = MPG;
}
public void setMake(String mke)
{
Make = mke;
}
public void setModel(String mdl)
{
Model = mdl;
}
public void createReservation(String CompName, int numDays, int numWeeks, int numMonths)
{
reserve = new Reservation(CompName,numDays, numWeeks, numMonths);
}
public boolean isReserved(Vehicle2[] vehicles, Reservation[] reserve)
{
return !(reserve == null);
}
public String toString()
{  
if (reserve == null)
{
return getMake() + " " + getModel() + " " + getVin() + "Is not reserved";
}
else
{
return getMake() + " " + getModel() + " " + getVin() + "Is reserved";
}
}
public double calcRentalCost(double total, double numDays, double numWeeks, double numMonths)
{
total= (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);
return total;
}
}

>Car:

package vehicle2;
public class Car extends Vehicle2
{
double DailyCost;
double WeeklyCost;
double MonthlyCost;
int NumSeats;
public Car(int MPG, int seats, String mke, String mdl)
{
super(MPG, mke,mdl);
NumSeats = seats;
reserve = null;
}
public int getNumSeats()
{
return NumSeats;
}
public void setDailyCost()
{
DailyCost = 24.95;
}
public void setWeeklyCost()
{
WeeklyCost = 149.95;
}
public void setMonthlyCost()
{
MonthlyCost = 514.95;
}
public void setNumSeats(int seats)
{
NumSeats = seats;
}
}

>SUV

package vehicle2;
public class SUV extends Vehicle2
{
double DailyCost;
double WeeklyCost;
double MonthlyCost;
int NumSeats;
public SUV(int MPG, int seats, String mke, String mdl)
{
super(MPG, mke,mdl);
NumSeats = seats;
reserve = null;
}
public void setDailyCost()
{
DailyCost = 29.95;
}
public void setWeeklyCost()
{
WeeklyCost = 189.95;
}
public void setMonthlyCost()
{
MonthlyCost = 679.95;
}
public void setNumSeats(int seats)
{
NumSeats = seats;
}
}

Truck

package vehicle2;
public class Truck extends Vehicle2
{
double DailyCost;
double WeeklyCost;
double MonthlyCost;
int NumSeats;
public Truck(int MPG, int seats, String mke, String mdl)
{
super(MPG, mke,mdl);
NumSeats = seats;
reserve = null;
}
public void setDailyCost()
{
DailyCost = 34.95;
}
public void setWeeklyCost()
{
WeeklyCost = 224.95;
}
public void setMonthlyCost()
{
MonthlyCost = 797.95;
}
public void setNumrCap(int seats)
{
NumSeats = seats;
}
}

Reservation

package vehicle2;
public class Reservation
{
String companyName;
int numDays, numWeeks, numMonths;
public Reservation(String compName, int nDay, int nWeek, int nMonth)
{
companyName = compName;
numDays = nDay;
numWeeks = nWeek;
numMonths = nMonth;
}
public int getnumDays()
{
return numDays;
}
public int getnumWeeks()
{
return numWeeks;
}
public int getnumMonths()
{
return numMonths;
}
public String getcompanyName()
{
return companyName;
}
}

Vehicle2App

package vehicle2;
import java.util.*;
public class Vehicle2App
{
public static void displayVehicles(Vehicle2[] vehicles, Reservation[] reserve)
{
for (int x = 1; x <= 25; x++)
{
if (isReserved(vehicles, reserve) == true)
{
System.out.println("Vehicle " + x + ": " + vehicles[x - 1] + ", is currently reserved");
}
else
{
System.out.println("Vehicle " + x + ": " + vehicles[x - 1] + ", is not reserved");
}
}
}
public static int findNext(int loc)
{
loc = 0;
for (int x = 0; x <= 24; x++)
{
x = loc + 1;
return x;
}
return 0;
}
public static void main(String[] args)
{
String Make, Model, Company_name;
int cmd, Selection, total_cost, Vin, MilePG, seats;
Vehicle2[] vehicles = new Vehicle2[25];
Scanner input = new Scanner(System.in);
boolean quit = false;
int loc = 0;
while(!quit)
{
System.out.println(" 1- Enter a new vehicle 2- Display all vehicles 3- Reserve a specific vehicle (by a specific company). 4- Display itemized list and total cost of all vehicles reserved for a specified company. 5- Quit");
cmd = input.nextInt();
if(cmd==5)
{
quit = true;
}
else
{
switch(cmd)
{
case 1: System.out.print("Enter(1)Car, (2)SUV, (3)Truck:");
Selection = input.nextInt();
switch(Selection)
{
case 1: System.out.print("Enter the make of the car:");
Make = input.next();
System.out.print("Enter the model of the car:");
Model = input.next();
System.out.print("Enter the number of seats:");
seats = input.nextInt();
System.out.print("Enter the MPG:");
MilePG = input.nextInt();
loc = findNext(loc);
vehicles[loc] = new Car(MilePG, seats, Make, Model);
break;
case 2: System.out.print("Enter the make of the SUV:");
Make = input.next();
System.out.print("Enter the model of the SUV:");
Model = input.next();
System.out.print("Enter the number of seats:");
seats = input.nextInt();
System.out.print("Enter the MPG:");
MilePG = input.nextInt();
loc = findNext(loc);
vehicles[loc] = new SUV(MilePG, seats, Make, Model);
break;
case 3: System.out.print("Enter the make of the Truck:");
Make = input.next();
System.out.print("Enter the model of the Truck:");
Model = input.next();
System.out.print("Enter the number of seats:");
seats = input.nextInt();
System.out.print("Enter the MPG:");
MilePG = input.nextInt();
loc = findNext(loc);
vehicles[loc] = new Truck(MilePG, seats, Make, Model);
break;
}
break;
case 3: System.out.print("Enter the vin of the vehicle to reserve:");
Vin = input.nextInt();
System.out.println("How many months, weeks or days would you like to rent for? ");
System.out.println("Months(if none type 0)?");
int numMonths = input.nextInt();
System.out.println("Weeks(if none type 0)?");
int numWeeks = input.nextInt();
System.out.println("Days(if none type 0)?");
int numDays = input.nextInt();
case 4: System.out.print("Enter Company name: ");
String compName = input.next();
//double calcRentalCost = total_cost;
//calcRentalCost = (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);
//displayVehicles(compName);
//System.out.println("Total cost for all vehicles: $" + total_cost);
}
}
}
System.out.println("bye");
}
// public static boolean isReserved(Vehicle2[] vehicles, Reservation[] reserve)
{
// for (int x = 0; x <= vehicles.length; x++)
{
// if ((vehicles[x].Vin) == (reserve[0].Vin))
{
// return true;
// }
// else
{
// return false;
// }
// }
// return false;
// }
}
}

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