public class Vehicle {
String engine;
int wheels;
int seats;
String fuelTank;
boolean lights;
// Constructor for Vehicle
public Vehicle(String engine, int wheels, int seats, String fuelTank, boolean lights) {
this.engine = engine;
this.wheels = wheels;
this.seats = seats;
this.fuelTank = fuelTank;
this.lights = lights;
}
public void displaySpecs() {
System.out.println("Engine: " + engine);
System.out.println("Wheels: " + wheels);
System.out.println("Seats: " + seats);
System.out.println("Fuel Tank Capacity: " + fuelTank);
System.out.println("Lights present: " + lights);
}
}
public class Bike extends Vehicle {
String handle;
public Bike(String engine, int wheels, int seats, String fuelTank, boolean lights, String handle) {
super(engine, wheels, seats, fuelTank, lights);
this.handle = handle;
}
public void displayBikeSpecs() {
displaySpecs();
System.out.println("Handle: " + handle);
}
}
public class Car extends Vehicle {
String steering;
String musicSystem;
String seatBelt;
String airConditioner;
String fridge;
String entertainmentSystem;
public Car(String engine, int wheels, int seats, String fuelTank, boolean lights,
String steering, String musicSystem, String seatBelt,
String airConditioner, String fridge, String entertainmentSystem) {
super(engine, wheels, seats, fuelTank, lights);
this.steering = steering;
this.musicSystem = musicSystem;
this.seatBelt = seatBelt;
this.airConditioner = airConditioner;
this.fridge = fridge;
this.entertainmentSystem = entertainmentSystem;
}
public void displayCarSpecs() {
displaySpecs();
System.out.println("Steering: " + steering);
System.out.println("Music System: " + musicSystem);
System.out.println("Seat Belt: " + seatBelt);
System.out.println("Air Conditioner: " + airConditioner);
System.out.println("Fridge: " + fridge);
System.out.println("Entertainment System: " + entertainmentSystem);
}
}
public class Truck extends Vehicle {
String steering;
String musicSystem;
String seatBelt;
String airConditioner;
String container;
public Truck(String engine, int wheels, int seats, String fuelTank, boolean lights,
String steering, String musicSystem, String seatBelt, String airConditioner, String container) {
super(engine, wheels, seats, fuelTank, lights);
this.steering = steering;
this.musicSystem = musicSystem;
this.seatBelt = seatBelt;
this.airConditioner = airConditioner;
this.container = container;
}
public void displayTruckSpecs() {
displaySpecs();
System.out.println("Steering: " + steering);
System.out.println("Music System: " + musicSystem);
System.out.println("Seat Belt: " + seatBelt);
System.out.println("Air Conditioner: " + airConditioner);
System.out.println("Container: " + container);
}
}
public class Main {
public static void main(String[] args) {
Bike bike = new Bike("500cc Engine", 2, 1, "10L", true, "Drop Handle");
Car car = new Car("2000cc Engine", 4, 5, "50L", true, "Power Steering",
"Premium Audio", "Standard", "Dual Zone", "Mini Fridge", "Touch Screen");
Truck truck = new Truck("4000cc Engine", 6, 3, "150L", true, "Hydraulic Steering",
"Advanced Audio", "Heavy Duty", "Refrigerated", "20ft Container");
System.out.println("----- Bike Specifications -----");
bike.displayBikeSpecs();
System.out.println("\n----- Car Specifications -----");
car.displayCarSpecs();
System.out.println("\n----- Truck Specifications -----");
truck.displayTruckSpecs();
}
}