-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.java
More file actions
50 lines (41 loc) · 1.19 KB
/
Copy pathMonster.java
File metadata and controls
50 lines (41 loc) · 1.19 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
package udemy;
import java.util.ArrayList;
import java.util.List;
public class Monster implements ISaveable {
private String name;
private int hitPoints;
private int strength;
public Monster(String name, int hitPoints, int strength) {
this.name = name;
this.hitPoints = hitPoints;
this.strength = strength;
}
public String getName() {
return name;
}
public int getHitPoints() {
return hitPoints;
}
public int getStrength() {
return strength;
}
public String toString(){
return ("Monster{name="+this.name+", hitPoints="+this.hitPoints+", strength="+this.strength+"}");
}
@Override
public List<String> write() {
List<String> values = new ArrayList<String>();
values.add(0,this.name);
values.add(1,""+this.hitPoints);
values.add(2,""+this.strength);
return values;
}
@Override
public void read(List<String> values) {
if(values != null && values.size()>0){
this.name = values.get(0);
this.hitPoints = Integer.parseInt(values.get(1));
this.strength = Integer.parseInt(values.get(2));
}
}
}