public interface Car {
String brand="TATA";
String model="safari";
long cost=720000;
void showCar();
}
public class BasicCar implements Car {
public void showCar() {
System.out.println("Brand="+brand);
System.out.println("Model="+model);
System.out.println("Cost="+cost);
}
}
public class CarDecorator implements Car {
Car c;
CarDecorator(Car c){
this.c=c;
}
@Override
public void showCar() {
c.showCar();
}
}
public class MountainCar extends CarDecorator {
boolean suspension=false;
String gasType="Normal";
String horsePower="1000CC";
String engineType="Diesel";
String engineModel="BS4";
MountainCar(Car c) {
super(c);
}
public void showCar() {
System.out.println("Mountain car details");
c.showCar();
showMountainCar();
}
public void showMountainCar() {
System.out.println("Supension="+suspension);
System.out.println("GasType="+gasType);
System.out.println("Horse Power="+horsePower);
System.out.println("Engine type="+engineType);
System.out.println("Engine model="+engineModel);
}
}
public class SportsCar extends CarDecorator {
boolean suspension=true;
String gasType="Nitro";
String horsePower="1700CC";
String engineType="Petrol";
String engineModel="BS6";
SportsCar(Car c) {
super(c);
}
public void showCar() {
System.out.println("Sports car details");
c.showCar();
showSportsCar();
}
public void showSportsCar() {
System.out.println("Supension="+suspension);
System.out.println("GasType="+gasType);
System.out.println("Horse Power="+horsePower);
System.out.println("Engine type="+engineType);
System.out.println("Engine model="+engineModel);
}
}