Question: Hand-write two Java classes, Car and Truck. They are both subclasses of Vehicle. /*******This is Vehicle class *********/ public class Vehicle { private String registrationNumber;

Hand-write two Java classes, Car and Truck. They are both subclasses ofHand-write two Java classes, Car and Truck. They are both subclasses of Vehicle.

/*******This is Vehicle class *********/

public class Vehicle {

private String registrationNumber;

private String ownerName;

private double price;

private int yearManufactured;

public Vehicle() {

registrationNumber="";

ownerName="";

price=0.0;

yearManufactured=0;

}

public Vehicle(String registrationNumber, String ownerName, double price, int yearManufactured) {

this.registrationNumber=registrationNumber;

this.ownerName=ownerName;

this.price=price;

this.yearManufactured=yearManufactured;

}

public String getRegistrationNumber() {

return registrationNumber;

}

public String getOwnerName() {

return ownerName;

}

public double getPrice() {

return price;

}

public int getYearManufactured() {

return yearManufactured;

}

public void setRegistrationNumber(String registrationNumber) {

this.registrationNumber=registrationNumber;

}

public void setOwnerName(String ownerName) {

this.ownerName=ownerName;

}

public void setPrice(double price) {

this.price=price;

}

public void setYearManufactured(int yearManufactured) {

this.yearManufactured=yearManufactured;

}

public String toString() {

return " Registration number:"+ registrationNumber +" Owner Name:"+ownerName+" Price:"+

price+" year manufactured"+yearManufactured;

}

}

3. (5 pts Inheritance) Hand-write two Java classes, Car and Truck. They are both subclasses of Vehicle. a. A car has an additional instance variable, numberOfDoors. b. A truck has an additional instance variable, numberOfAxles c. Write a constructor that requires input for the instance variables of each class (including receiving registration number, owner name, price, and year manufactured, and calling super with them) d. Write getters and setters for all instance variables for both classes (e.g., Car and Truck)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!