Reputation: 148
I got a bit rusty in Java, have not program anything like this for ages.I'am trying to create a simple car park manager program and implement following classes Vehicle and the sub classes Car, Van,Motorbike(those extend Vehicle Class. The Car class should hold information about the number of the doors of the car and the color. The Van class should include information about the cargo volume of the van. The class Motorbike should have information about the engine size. The program should allow to add Vehicle to the parking lot, delete the vehicle and print the list of currently parked vehicles and give information if parked vehicles are cars bikes or vans. I have designed all the classes. However i have a problem with the user input on this. User while adding vehicle should be allowed to input car bike or van model, registration plate, the color of the vehicle, also number of doors. And program should print the information when corresponding menu option is chosen. Can you please have a look at the code i have so far, any help will be much appreciated. The problem i have is to get the user to input all the requested information.
public class Vehicle {
private String carBrand;
private String regPlate;
// default constructor
public Vehicle() {
}
// constructor
public Vehicle(String carBrand, String regPlate) {
this.carBrand = carBrand;
this.regPlate = regPlate;
}
//getters
public String getCarBrand() {
return carBrand;
}
public String getRegPlate() {
return regPlate;
}
//setters
public void setCarBrand(String carBrand) {
this.carBrand = carBrand;
}
public void setColor(String regPlate) {
this.regPlate = regPlate;
}
}
...
public class Main {
public static void main(String[] args) {
CarParkManager myCarPark = new CarParkManager();
Scanner input = new Scanner(System.in);
int menu;
String model;
do {
System.out.println("WELCOME TO PARKING MANAGEMENT");
System.out.println("1: To Park Vehicle");
System.out.println("2: To Departure");
System.out.println("3: Show All Perked Vehicles");
System.out.println("0: To Exit");
System.out.print("Enter your choice: ");
menu = input.nextInt();
System.out.println();
switch (menu) {
case 1: {
String vType;
System.out.println("Please choose The Vehicle type");
System.out.println("C = Car");
System.out.println("B = Motorbike");
System.out.println("V = VAN");
vType = input.next();
if (vType.equals("C")) {
System.out.println("Enter Model");
model = input.next();
System.out.println("Enter Colour");
String colour = input.next();
System.out.println("Enter Reg Plate");
String regPlate = input.next();
System.out.println("Door Number");
int doorNumber = input.nextInt();
} else if (vType.equals("B")) {
} else if (vType.equals("V")) {
}
break;
}
case 2: {
break;
}
case 3: {
System.out.println("List of All Parked Vehicles : ");
myCarPark.printParkedVehicleDetails();
break;
}
case 0: {
System.out.println("\nThank you!\n");
break;
}
default: {
System.out.println("Invalid option!\n");
break;
}
}
} while (menu != 0);
}
}
Upvotes: 1
Views: 23196
Reputation: 29266
getDetailsFromUser
on the VehicleThe specific subclass (Van etc) can ask the user what ever questions they need in order to populate themselves.
Upvotes: 3