Answer:
Explanation:
The following program is written in Java. Since there was not much information provided in the question I created a Vehicle superclass with a couple of subclasses for the different types of vehicles (motorcycle, sedan, truck). Each one having its own unique attributes. The vehicle class also has an attribute for the position of the vehicle in the race.
class Vehicle {
int year, wheels, position;
public Vehicle(int year, int wheels, int position) {
this.year = year;
this.wheels = wheels;
this.position = position;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getWheels() {
return wheels;
}
public void setWheels(int wheels) {
this.wheels = wheels;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}
class Motorcycle extends Vehicle {
String manufacturer;
double speed;
public Motorcycle(int year, int wheels, int position) {
super(year, wheels, position);
}
public Motorcycle(int year, int wheels, int position, String manufacturer, double speed) {
super(year, wheels, position);
this.manufacturer = manufacturer;
this.speed = speed;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
}
class Sedan extends Vehicle {
int passengers;
String manufacturer;
double speed;
public Sedan(int year, int wheels, int position) {
super(year, wheels, position);
}
public Sedan(int year, int wheels, int position, int passengers, String manufacturer, double speed) {
super(year, wheels, position);
this.passengers = passengers;
this.manufacturer = manufacturer;
this.speed = speed;
}
public int getPassengers() {
return passengers;
}
public void setPassengers(int passengers) {
this.passengers = passengers;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
}
class Truck extends Vehicle {
int passengers;
String manufacturer;
double speed;
public Truck(int year, int wheels, int position) {
super(year, wheels, position);
}
public Truck(int year, int wheels, int position, int passengers, String manufacturer, double speed) {
super(year, wheels, position);
this.passengers = passengers;
this.manufacturer = manufacturer;
this.speed = speed;
}
public int getPassengers() {
return passengers;
}
public void setPassengers(int passengers) {
this.passengers = passengers;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
}