Question
just need some help , in java on intellij i already have done code for other checkpoints which i have a vehicle class, car classs
just need some help , in java on intellij
i already have done code for other checkpoints which i have a vehicle class, car classs and vehicle tester class just need help with this checkpoint for the classes vehicleDB and holdenDB and other modifications to already done code in which ihave attachted to the bottom of the question, thanks
ask 4/4: Checkpoint 45
Add a class called VehicleDB which can store 5 Vehicle objects (You must use and array and you will need to keep track of how many vehicles have been added). It should include the following methods:
a method called addVehicle which adds a Vehicle, or any of its descendants, to the database (see example below).
a method that increases the size of the database by 10 if it becomes full.
a method called print which prints all the Vehicles in the database (see example below).
Hint
Add getters for the size of the database and the number of vehicles in it.
Modify the class VehicleTester to be:
public class VehicleTester { public static void main(String[] args) { VehicleDB vdb = new VehicleDB(); vdb.addVehicle(new Car(1200, "Holden", "sedan", "Barina")); vdb.addVehicle(new Vehicle(1500, "Mazda")); vdb.addVehicle(new Car(1600, "Nissan", "suv", "X-Trail")); vdb.addVehicle(new Vehicle(1800, "Jeep")); vdb.addVehicle(new Vehicle(1000, "Suzuki")); vdb.addVehicle(new Car(2000, "Kia", "sedan", "Cerato")); vdb.print(); } }
The following output should be produced when the program is run: === Vehicle Data Base === Vehicle Info: capacity = 1200cc make = Holden type = sedan model = Barina Vehicle Info: capacity = 1500cc make = Mazda Vehicle Info: capacity = 1600cc make = Nissan type = suv model = X-Trail Vehicle Info: capacity = 1800cc make = Jeep Vehicle Info: capacity = 1000cc make = Suzuki Vehicle Info: capacity = 2000cc make = Kia type = sedan model = Cerato
Add a class called HoldenDB which inherits from (extends) VehicleDB. It should include:
a constructor which has no formal parameters and which calls its parents constructor with an actual parameter of 20
a method called addCar which takes three parameters (see example below), creates a Car object and adds it to the database by making use one of its parents methods.
an overriden version of the print method that prints === Holdens Only === and then calls its parents print method
Add the following code at the bottom the class VehicleTester:
HoldenDB hdb = new HoldenDB(); hdb.addCar(1200, "sedan", "Barina"); hdb.addCar(3800, "wagon", "Commodore"); hdb.print();
The following output should be appended to the output above when the program is run: === Holdens Only === === Vehicle Data Base === Vehicle Info: capacity = 1200cc make = Holden type = sedan model = Barina Vehicle Info: capacity = 3800cc make = Holden type = wagon model = Commodore
code i already have in other classes
public class Car extends Vehicle { private String type; private String model; public Car(int capacity, String make, String type, String model) { super(capacity, make); this.type = type; this.model = model; } public void print() { super.print(); System.out.println(" type = " + type); System.out.println(" model = " + model); } public void setCapacity(int capacity) { System.out.println("Cannot change the engine capacity of a car"); } }
public class Vehicle { // parent class private int capacity; private String make; public Vehicle(int theCapacity, String theMake) { capacity = theCapacity; make = theMake; } public void setCapacity(int capacity) { System.out.println("Changing vehicle engine capacity: new capacity = " + capacity); this.capacity = capacity; } public void print() { System.out.println("Vehicle Info:"); System.out.println(" capacity = " + capacity + "cc"); System.out.println(" make = " + make); } }
public class VehicleTester { public static void main(String[] args) { VehicleDB vdb = new VehicleDB(); vdb.addVehicle(new Car(1200, "Holden", "sedan", "Barina")); vdb.addVehicle(new Vehicle(1500, "Mazda")); vdb.addVehicle(new Car(1600, "Nissan", "suv", "X-Trail")); vdb.addVehicle(new Vehicle(1800, "Jeep")); vdb.addVehicle(new Vehicle(1000, "Suzuki")); vdb.addVehicle(new Car(2000, "Kia", "sedan", "Cerato")); vdb.print(); HoldenDB hdb = new HoldenDB(); hdb.addCar(1200, "sedan", "Barina"); hdb.addCar(3800, "wagon", "Commodore"); hdb.print(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started