-
Notifications
You must be signed in to change notification settings - Fork 0
/
Droid.java
63 lines (52 loc) · 1.68 KB
/
Droid.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
/*This project involves a simple Droid (robot)
that can be activated, charged, and hover above ground.
This project creates some base line behaviors of the droid.
*/
public class Droid{
// instance variable
int batteryLevel;
// constructor
public Droid(){
//100 is the maximun percentage the battery can be charged
batteryLevel = 100;
}
public void activate() {
System.out.println("Activated. Ready for your command!");
batteryLevel = batteryLevel - 5;
System.out.println("Battery level is " + batteryLevel + " percent");
}
public void chargeBattery(int hours){
System.out.println("Droid charging.....");
batteryLevel = batteryLevel + hours;
if ( batteryLevel == 100){
batteryLevel = 100;
System.out.println("Battery Full " + 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(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 + " percent");
}
}
public static void main(String[] args){
//object Mega is name of droid
Droid Mega = new Droid();
Mega.activate();
//5 is for the amount of hours battery will be charging
Mega.chargeBattery(5);
//2 is for the altitude the droid is hovering in feet
Mega.hover(2);
}
}