-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkyBison.java
More file actions
92 lines (75 loc) · 2.03 KB
/
SkyBison.java
File metadata and controls
92 lines (75 loc) · 2.03 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
public class SkyBison {
private String name;
private int fluffiness;
private int health;
public SkyBison(String n, int f, int h) {
name = n; // instantiate the variables
fluffiness = f;
if (h<0) { //makes health 0 if provided negative number
health = 0;
}
else {
health = h;
}
}
public SkyBison(String n) {
health = 100;
fluffiness = 100;
name = n;
}
//setter
public void setName(String n) {
name = n;
}
public void setFluffiness(int f) {
fluffiness = f;
}
public void setHealth(int h) {
if (h<0) {
health = 0;
}
else {
health = h;
}
}
// getter
public String getName() {
return name;
}
public int getFluffiness() {
return fluffiness;
}
public int getHealth() {
return health;
}
public void eatSnack(int[] healtharray) {
for (int i=0; i<healtharray.length; i++) {
this.health += healtharray[i];
}
}
public void eatSnack(int food) {
this.health += food;
}
public void fly(int hours) {
this.health -= 10*hours;
if (this.health <0) {
this.health = 0;
}
}
public static void main(String[] args) {
SkyBison appa = new SkyBison("appa", 100, 3);
SkyBison oogi = new SkyBison("oogi");
int[] eating = {2,3,4};
appa.eatSnack(eating);
oogi.eatSnack(3);
appa.fly(6);
appa.setHealth(100);
oogi.setFluffiness(20);
appa.setName("Blueberry Spicehead");
System.out.println("appa's health: " + appa.getHealth());
System.out.println("oogis' health: " +oogi.getHealth());
System.out.println("appa's fluffiness: " + appa.getFluffiness());
System.out.println("oogis' fluffiness: " +oogi.getFluffiness());
System.out.println("appa's name changed to: " + appa.getName());
}
}