Question: just need some help = in java on intellih, thanks Task 1/4: Checkpoint 42 Copy the following code into the skeleton classes VehicleTester and Vehicle
just need some help = in java on intellih, thanks
Task 1/4: Checkpoint 42
Copy the following code into the skeleton classes VehicleTester and Vehicle
public class VehicleTester { public static void main(String[] args) { Car car1 = new Car(1200, "Holden", "sedan", "Barina"); Car car2 = new Car(1500, "Mazda", "sedan", "323"); car1.print(); car2.print(); } } public class Vehicle { // parent class private int capacity; private String make; public Vehicle(int theCapacity, String theMake) { capacity = theCapacity; make = theMake; } public int getCapacity() { return capacity; } public String getMake() { return make; } public void print() { System.out.println("Vehicle Info:"); System.out.println(" capacity = " + capacity + "cc"); System.out.println(" make = " + make); } } Complete the definition of the class Car by adding
instance variables to store the type and model (both Strings) of the car
a constructor with the following header:
Car(int capacity, String make, String type, String model)
and which assigns the respective instance variables. Note, the first statement in the constructor should be a call to the constructor of the super class (Vehicle):
super( ...
Getters and setters for the instance variables.
The following output should be produced when the program is run (the indents are 2 spaces): Vehicle Info: capacity = 1200cc make = Holden Vehicle Info: capacity = 1500cc make = Mazda
Note that the class Car does not have a print method and thus the type and model are not printed. This will be added as part of the next task.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
