-
Notifications
You must be signed in to change notification settings - Fork 0
/
Automobile.java
86 lines (67 loc) · 2.19 KB
/
Automobile.java
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
Main Class
package com.company;
public class Main {
public static void main(String[] args) {
Automobile auto = new Automobile(20, "LandROver",
"2018", 200000, 10);
Car car = new Car( 150, "Audi", 10,
"Yes", "Yes", "1000kWatt",
"Yes", "1.5 inch");
auto.movement();
car.movement();
auto.speed(50);
car.speed(60);
}
}
Automobile Class
public class Automobile {
private double topSpeed;
private String brandName;
private String yearOfManufacture;
private double cost;
private double durability;
public Automobile(double topSpeed, String brandName, String yearOfManufacture,
double cost, double durability) {
this.topSpeed = topSpeed;
this.brandName = brandName;
this.yearOfManufacture = yearOfManufacture;
this.cost = cost;
this.durability = durability;
}
public void movement() {
System.out.println("Automobile.movement() was called and Automobile moves");
}
public void speed(int speed) {
System.out.println("The automobile is moving at a speed of : "+speed);
}
}
Car Class
package com.company;
public class Car extends Automobile {
private String SteeringWheel;
private String Moonroof;
private String BatterySize;
private String Headlamps;
private String GroundClearance;
public Car(double topSpeed, String brandName, double durability, String steeringWheel, String moonroof,
String batterySize, String headlamps, String groundClearance) {
super(topSpeed, brandName, durability, yearOfManufacture: 2018, cost: 1000000);
SteeringWheel = steeringWheel;
Moonroof = moonroof;
BatterySize = batterySize;
Headlamps = headlamps;
GroundClearance = groundClearance;
}
@Override
public void movement() {
System.out.println("Car is driven on roads");
super.movement();
}
public void carspeed(int speed) {
speed(speed);
}
@Override
public void speed(int speed) {
System.out.println("The car speed is: " + speed);
}
}