Problem Statement: Implementing Polymorphism using abstract class and interface
Define Vehicle interface,AbstractManufacturer abstract class,Car class,Bike class and VehicleService Class as given below:
Interface Vehicle
create abstract method. +maxSpeed(String type) : int
Abstract class AbstractManufacturer
Declare private properties.
name : String
modelName : String
type : String
Provide getter for all properties
Declare abstract method +getManufacturerInformation() : String
Car Class
Make the class as subclass of Vehicle and AbstractManufacturer.
Define parameterized constructor passing three parameters to initialize name,modelName and type.
Override the abstract methods and follow the instructions given as comments for the business logic.
Bike Class
Make the class as subclass of Vehicle and AbstractManufacturer.
Define parameterized constructor passing three parameters to initialize name,modelName and type.
public interface Vehicle {
int maxSpeed(String type);
}
public abstract class AbstractManufacturer {
private String name;
private String modelName;
private String type;
public AbstractManufacturer(String name, String modelName, String type) {
this.name = name;
this.modelName = modelName;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public abstract String getManufacturerInformation();
}
public class Car extends AbstractManufacturer implements Vehicle {
public Car(String name, String modelName, String type) {
super(name, modelName, type);
// TODO Auto-generated constructor stub
}
@Override
public int maxSpeed(String type) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getManufacturerInformation() {
// TODO Auto-generated method stub
return null;
}
}
public class Bike extends AbstractManufacturer implements Vehicle {
public Bike(String name, String modelName, String type) {
super(name, modelName, type);
// TODO Auto-generated constructor stub
}
@Override
public int maxSpeed(String type) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getManufacturerInformation() {
// TODO Auto-generated method stub
return null;
}
}
Comments
Leave a comment