-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarehouse.java
More file actions
97 lines (84 loc) · 1.83 KB
/
warehouse.java
File metadata and controls
97 lines (84 loc) · 1.83 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
abstract class Robot
{
private String batteryID;
protected double chargeLevel;
Robot(String id, double cl)
{
batteryID = id;
chargeLevel = cl;
}
abstract void work(double cons);
void reportStatus()
{
}
abstract void performTask();
}
class DroneRobot extends Robot
{
DroneRobot(String id, double cl)
{
super(id, cl);
}
void work(double cons)
{
chargeLevel = chargeLevel - cons;
}
void performTask()
{
if(chargeLevel < 15)
{
System.out.println("Insufficient Charge!");
}
else
{
work(15);
System.out.println("Moving...");
}
}
}
class GroundRobot extends Robot
{
boolean SurfaceCheck;
GroundRobot(String id, double cl, boolean sc)
{
super(id, cl);
SurfaceCheck = sc;
}
void work(double cons)
{
chargeLevel = chargeLevel - cons;
}
void performTask()
{
if(chargeLevel < 5)
{
System.out.println("Insufficient Charge!");
}
else if(SurfaceCheck == false)
{
System.out.println("Surface not Clear!!");
}
else
{
work(15);
System.out.println("Moving...");
}
}
}
public class warehouse
{
public static void main(String[] args)
{
Robot[] fleet = new Robot[3];
int total = 0;
Robot obj1 = new GroundRobot("G1", 100, true);
Robot obj2 = new DroneRobot("A2", 90);
fleet[total++] = obj1;
fleet[total++] = obj2;
for(Robot r : fleet)
{
r.performTask();
r.reportStatus();
}
}
}