Professional Documents
Culture Documents
Phase 1 Final Code
Phase 1 Final Code
Phase 1 Final Code
import java.util.Scanner;
String choice;
int chice2;
do {//second loop for the services the customer wants
for their contracts
System.out.println("---------------------------------------------
-----------");
System.out.println("Enter the number for your choice
of service");
System.out.println("1- Add a rental contract.");
System.out.println("2- Add a vehicle to a
contract.");
System.out.println("3- Remove a vehicle from a
contract.");
System.out.println("4- Search for a vehicle's
information.");
System.out.println("5- Print customer's
information.");
System.out.println("6- Print receipt for all
contracts.");
System.out.println("7-Exit");
System.out.println("---------------------------------------------
-----------");
chice2 = input.nextInt();
switch (chice2) {
case 1:
System.out.println("Enter the number of vehicles
you would like to add to your new contract. ");//to collect
information for the RenntalContract object.
if (selectedContract != null) {
if (answer.equalsIgnoreCase("car")) {
if (selectedContract.addVehicle(car)) {
System.out.println("Car added
successfully!");
} else
System.out
.println("sorry cannot add car, you
have reached your limit in this contract.");
} else if
(answer.equalsIgnoreCase("motorcycle")) {//to collect information
for motorcycle object.
System.out.println("Enter motorcycle
Brand.");
String brand = input.next();
System.out.println("Enter the number of
rental days ? ");
int numOfrent = input.nextInt();
System.out.println("Enter the color of the
motorcycle.");
String color = input.next();
System.out.println("Enter the number of
wheels.");
int numOfWheels = input.nextInt();
if (selectedContract.addVehicle(motorcycle))
System.out.println("Motorcycle added
successfully!");
else
System.out.println(
"sorry cannot add motorcycle, you
have reached your limit in this contract.");
}
} else
System.out.println("Contract not
found.");//when the getRentalContract method returns null.
break;
case 3:
System.out.println("Enter the contract number from
which you want to remove a vehicle:");//sees which contract in
the rentalHistory array to remove the vehicle to.
int contractNumberToRemove = input.nextInt();
RentalContract contractToRemoveFrom =
c1.getRentalContract(contractNumberToRemove);//returns object
RentalContracl from rentalHistory if rental contract number
matched
if (contractToRemoveFrom != null) {
System.out.println(
"Enter the vehicle's ID you want to
remove from the contract: \n (vehicle's ID format is: first
letter of the vehicle's brand capitalized_number of days the
vehicle is rented for.)");
String vehicleIdToRemove = input.next();
if
(contractToRemoveFrom.removeVehicle(vehicleIdToRemove)) {
System.out.println("Vehicle successfully
removed from the contract!");
} else {
System.out.println("Vehicle not found in the
contract.");
}
} else {
System.out.println("Contract not found!");
}
break;
case 4:
contractToSearchIn.printVehicle(contractToSearchIn.searchVehicle(
vehicleIdToSearch));// the parameters of printVehicle are
searchVehicle method because it returns the index of the vehicle
we want to search for
} else
System.out.println("Vehicle not found in the
contract.");
} else {
System.out.println("Contract not found!");
}
break;
case 5:
System.out.println(c1.toString());
break;
case 6:
break;
case 7:
System.out.println("Thank you for working with us,
Goodbye :D");
System.exit(0);
break;
default:
System.out.println("Invalid choice, please try
again");
}
} while (true);
input.close();
}
}
///////////////////////////////////
Customer Class
return sum;
///////////////////////////////////
RentalContract Class
return false;
return false;
}
if (vehicleList[i].getvehicleID().equals(id) &&
vehicleList[i] != null)
return i;
return -1;
}
return total;
}
///////////////////////////////////
Vehicle Class
this.brand = brand;
vehicleID = brand.toUpperCase().charAt(0) + "_" + days; //
so the user can look for the specified vehicle
this.color = color;
rentalCost = calculateRentalCost(days); // calculated
through abstract method in car and motorcycle
this.days = days;
}
///////////////////////////////////
Car Class
public class Car extends Vehicle {
return rentalCost;
}
///////////////////////////////////
Motorcycle Class
rentalCost = 30 * days;
return rentalCost;
}