Question: Create a class Vehicle. A Vehicle has a single instance variable of type String named vehicleType that describes the vehicle. It has an abstract method

Create a class Vehicle. A Vehicle has a single instance variable of type String named "vehicleType" that describes the vehicle.
It has an abstract method getTires that takes no parameters and returns an ArrayList object that describes each Tire of the vehicle. A Tire class has been provided. Vehicle has a single constructor that takes the vehicle type as a parameter.
Create a class Bicycle that extends Vehicle that has two Tires, both of type "skinny". Bicycle should have a single default constructor.
Create a class Dragster that extends Vehicle and has four Tires, two of type "slick" and two of type "medium". Dragster should have a single default constructor.
Create a class Tricycle that extends Vehicle and has three Tires, all three "normal". Tricycle should have a single default constructor
tire.java is package optionB;
public class Tire {
private String size;
public Tire(String size){
this.size = size;
}
public String getSize(){
return this.size;
}
@Override
public boolean equals(Object obj){
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass()!= obj.getClass())
return false;
Tire other =(Tire) obj;
if (size == null){
if (other.size != null)
return false;
} else if (!size.equals(other.size))
return false;
return true;
}
}
tester.java is
package optionB;
public class Tester {
public static void main(String[] args){
Vehicle bicycle = new Bicycle("Electric");
System.out.println(bicycle.getVehicleType());
for(Tire t : bicycle.getTires()){
System.out.println(t.getSize());
}
Vehicle dragster = new Dragster("TopFuel");
System.out.println(dragster.getVehicleType());
for(Tire t : dragster.getTires()){
System.out.println(t.getSize());
}
Vehicle tri = new Tricycle ("Gramma's Special");
System.out.println(tri.getVehicleType());
for(Tire t : tri.getTires()){
System.out.println(t.getSize());
}
}
}

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 Programming Questions!