-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDroid.java
More file actions
57 lines (44 loc) · 1.29 KB
/
Droid.java
File metadata and controls
57 lines (44 loc) · 1.29 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
//a simple java program to print out some of the behaviours of a Droid...
public class Droid{
int batteryLevel;
public Droid(){
batteryLevel = 100;
}
public void activate(){
System.out.println("Activated...How can I help you Dan?");
batteryLevel -= 5;
System.out.println("Battery level is: " + batteryLevel + " percent.");
}
public void chargeBattery(int hours){
System.out.println("Droid charging......");
batteryLevel += hours;
if (batteryLevel > 100){
batteryLevel = 100;
System.out.println("Battery level is: " + batteryLevel + "percent.");
}
else{
System.out.println("Battery level is: " + batteryLevel + "percent.");
}
}
public int checkBatteryLevel(){
System.out.println("Battery level is: " + batteryLevel + "percent.");
return batteryLevel;
}
public void hover(double feet){
if(feet >2){
System.out.println("Error! I cannot hover above 2 feet.");
}
else{
System.out.println("Hovering........");
}
batteryLevel -= 20;
System.out.println("Battery level is: " + batteryLevel + "percent.");
}
public static void main(String[] args){
Droid myDroid = new Droid();
myDroid.activate();
myDroid.chargeBattery(5);
myDroid.hover(2.1);
myDroid.checkBatteryLevel();
}
}