-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleSystem.java
More file actions
46 lines (46 loc) · 1.56 KB
/
Copy pathVehicleSystem.java
File metadata and controls
46 lines (46 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Vehicle {
String brand, model;
double price;
Vehicle(String brand, String model, double price) {
this.brand = brand;
this.model = model;
this.price = price;
}
void displayDetails() {
System.out.println(brand + " " + model + " costs " + price);
}
}
class Car extends Vehicle {
int seatingCapacity;
String fuelType;
Car(String brand, String model, double price, int seatingCapacity, String fuelType) {
super(brand, model, price);
this.seatingCapacity = seatingCapacity;
this.fuelType = fuelType;
}
@Override
void displayDetails() {
super.displayDetails();
System.out.println("Seating Capacity: " + seatingCapacity + ", Fuel Type: " + fuelType);
}
}
class ElectricCar extends Car {
int batteryCapacity;
int chargingTime;
ElectricCar(String brand, String model, double price, int seatingCapacity, String fuelType, int batteryCapacity, int chargingTime) {
super(brand, model, price, seatingCapacity, fuelType);
this.batteryCapacity = batteryCapacity;
this.chargingTime = chargingTime;
}
@Override
void displayDetails() {
super.displayDetails();
System.out.println("Battery: " + batteryCapacity + " kWh, Charging Time: " + chargingTime + " hours");
}
}
public class VehicleSystem {
public static void main(String[] args) {
ElectricCar tesla = new ElectricCar("Tesla", "Model S", 79999, 5, "Electric", 100, 2);
tesla.displayDetails();
}
}