-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle1.java
More file actions
80 lines (66 loc) · 1.91 KB
/
Copy pathVehicle1.java
File metadata and controls
80 lines (66 loc) · 1.91 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
public class Vehicle1 {
private String make;
private String model;
private int year;
private String fuelType;
// Constructor
public Vehicle1(String make, String model, int year, String fuelType) {
this.make = make;
this.model = model;
this.year = year;
this.fuelType = fuelType;
}
// Getters and Setters
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getFuelType() {
return fuelType;
}
public void setFuelType(String fuelType) {
this.fuelType = fuelType;
}
// Methods with sample implementation
public void fuelEfficiency() {
System.out.println("Calculating fuel efficiency...");
}
public void distanceTraverse() {
System.out.println("Calculating distance traversed...");
}
public void maxSpeed() {
System.out.println("Calculating maximum speed...");
}
// Optional: Override toString
@Override
public String toString() {
return "Vehicle1{" +
"make='" + make + '\'' +
", model='" + model + '\'' +
", year=" + year +
", fuelType='" + fuelType + '\'' +
'}';
}
// Main Method for Testing
public static void main(String[] args) {
Vehicle1 vehicle = new Vehicle1("Toyota", "Corolla", 2020, "Petrol");
System.out.println(vehicle);
vehicle.fuelEfficiency();
vehicle.distanceTraverse();
vehicle.maxSpeed();
}
}