-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDroid.java
More file actions
31 lines (28 loc) · 822 Bytes
/
Droid.java
File metadata and controls
31 lines (28 loc) · 822 Bytes
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
public class Droid {
String name;
int batteryLevel;
public Droid(String droidName) {
name = droidName;
batteryLevel = 100;
}
public void performTask(String task){
System.out.println(name + " is performing task: " + task);
batteryLevel = batteryLevel - 10;
}
public void energyReport(int energy){
System.out.println(name + " has a battery level of " + batteryLevel);
batteryLevel = batteryLevel - 36;
System.out.println(batteryLevel);
}
public String toString(){
return "Hello, I’m the droid: " + name;
}
public static void main(String[ ] args){
Droid codey = new Droid ("codey");
System.out.println(codey);
codey.performTask("running");
codey.performTask("singing");
Droid david = new Droid("David");
david.energyReport(36);
}
}