-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicles.java
More file actions
111 lines (77 loc) · 3.23 KB
/
Vehicles.java
File metadata and controls
111 lines (77 loc) · 3.23 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Base class Vehicle
class Vehicle {
protected String make;
protected String model;
protected int year;
protected String fuelType;
public Vehicle(String make, String model, int year, String fuelType) {
this.make = make;
this.model = model;
this.year = year;
this.fuelType = fuelType;
}
}
// Subclass Truck
class Truck extends Vehicle {
public Truck(String make, String model, int year, String fuelType) {
super(make, model, year, fuelType);
}
public void calculateFuelEfficiency(double distanceDriven, double fuelUsed) {
System.out.println( "Maximum Fuel Efficiency is: "+distanceDriven / fuelUsed);
}
public void Distance(int totalDistance) {
System.out.println("Total Distanced Covered is: "+totalDistance);
}
public void MaxSpeed(int maxSpeed) {
System.out.println("Maximum Speed is: "+maxSpeed);
}
}
// Subclass Car
class Car extends Vehicle {
public Car(String make, String model, int year, String fuelType) {
super(make, model, year, fuelType);
}
public void calculateFuelEfficiency(double distanceDriven, double fuelUsed) {
System.out.println( "Maximum Fuel Efficiency is: "+distanceDriven / fuelUsed);
}
public void Distance(int totalDistance) {
System.out.println("Total Distanced Covered is: "+totalDistance);
}
public void MaxSpeed(int maxSpeed) {
System.out.println("Maximum Speed is: "+maxSpeed);
}
}
// Subclass Motorcycle
class Motorcycle extends Vehicle {
public Motorcycle(String make, String model, int year, String fuelType) {
super(make, model, year, fuelType);
}
public void calculateFuelEfficiency(double distanceDriven, double fuelUsed) {
System.out.println( "Maximum Fuel Efficiency is: "+distanceDriven / fuelUsed);
}
public void Distance(int totalDistance) {
System.out.println("Total Distanced Covered is: "+totalDistance);
}
public void MaxSpeed(int maxSpeed) {
System.out.println("Maximum Speed is: "+maxSpeed);
}
}
public class Vehicles {
public static void main(String[] args) {
Truck truck = new Truck("Ford", "F150", 2022, "Gasoline");
Car car = new Car("Toyota", "Corolla", 2023, "Gasoline");
Motorcycle motorcycle = new Motorcycle("Harley-Davidson", "Sportster", 2021, "Gasoline");
System.out.println("Truck: " + truck.make + " " + truck.model + " " + truck.year + " " + truck.fuelType );
truck.Distance(1220);
truck.MaxSpeed(200);
truck.calculateFuelEfficiency(1220,140.0);
System.out.println("Car: " + car.make + " " + car.model + " " + car.year + " " + car.fuelType);
car.Distance(1600);
car.MaxSpeed(300);
car.calculateFuelEfficiency(1600,300.0);
System.out.println("Motorcycle: " + motorcycle.make + " " + motorcycle.model + " " + motorcycle.year + " " + motorcycle.fuelType);
motorcycle.Distance(2000);
motorcycle.MaxSpeed(260);
motorcycle.calculateFuelEfficiency(2000,260.0);
}
}