Im currently working on creating a Car Rental program. Im nearly done but I have some errors that I need help fixing.
There are three vehicle categories: cars, SUVs, and trucks.
Each one needs the make/model, miles per gallon, num of seats, vehicle number (VIN)
- must allow for the entry of new vehicles of a given type.
- must be able to display the all the information related to a given vehicle type,
including make/model, miles per gallon, vehicle seats, daily rate, weekend rate, weekly rate,
and whether currently reserved or not.
- must allow for vehicle reservation for a number of days, weeks, or months.
- User must enter the VIN of the vehicle to reserve, the amount of time of the rental
period desired, and the company name reserving the vehicle.
- must allow a given company to enter the company name, and get a list of the complete cost of all the vehicles reserved for rental.
Im fairly new to programming and Im having alot of trouble with inserting the functions into right positions in the VehicleApp to make everything work. Also, Im having some trouble understanding how to connect the car, truck, and SUV classes to the vehicle app so that I can calculate the total cost. I worked on for a long while last night and after a while I started just plugging things in where I thought they might go in order to get output.
Im having a great amount of trouble figuring out how to actually reserve the cars and keep them in the array while the program is running. Im sure this has to do with the VehicleAppDoes anyone know how to do this?
Im also having an issue with calcRentalCost. This is what I have so far:
double calcRentalCost = (numDays * DailyCost) + (numWeeks * WeeklyCost) + (numMonths * MonthlyCost);
However, since the app is static it wont allow for me to get the costs from another part of the program. What should I do?
ANY HELP WOULD BE GREATLY APPRECIATED.
This is what I have so far:
Vehicle2:
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 abstract double getDailyCost();
//public abstract double getWeeklyCost();
//public abstract double getMonthlyCost();
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;
}
}
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;
}
}
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;
}
}
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 \n 2- Display all vehicles \n 3- Reserve a specific vehicle (by a specific company). \n 4- Display itemized list and total cost of all vehicles reserved for a specified company. \n 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;
}
//case 2: displayVehicles(vehicles);
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? \n");
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();
//reserveVehicle(Vin);// Supporting function
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("Goodbye");
}
// 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;
// }
}
}
Let me know what you think.