-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDroid.java
More file actions
60 lines (51 loc) · 1.18 KB
/
Droid.java
File metadata and controls
60 lines (51 loc) · 1.18 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
public class Droid
{
int batteryLevel;
public Droid()
{
batteryLevel = 100;
}
//functions of droid
public void activate()
{
System.out.println("Activated. How can I help you?");
batteryLevel = batteryLevel - 5;
System.out.println("Battery level is" + batteryLevel);
}
public void chargeBattery(int hours)
{
System.out.println("Droid Charging.....");
batteryLevel = batteryLevel + hours;
if (batteryLevel > 100)
{
batteryLevel = 100;
System.out.println("Battery level is" + batteryLevel);
}
else{
System.out.println("batteryLevel is" + batteryLevel);
}
}
public int checkBatteryLevel()
{
System.out.println("Battery Level currently is : ");
return batteryLevel;
}
public void hover(int feet)
{
if(feet > 2){
System.out.println("Error! I cannot hover above 2 feet!");
}
else{
System.out.println("Hovering.....");
}
batteryLevel = batteryLevel - 20;
System.out.println("Battery level is :" + batteryLevel);
}
public static void main(String[] args)
{
Droid MyDroid = new Droid();
MyDroid.activate();
MyDroid.chargeBattery(5);
MyDroid.hover(1);
}
}