-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
63 lines (52 loc) · 1.44 KB
/
Animal.java
File metadata and controls
63 lines (52 loc) · 1.44 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
public class Animal {
// constructor
public Animal() {
isAsleep = false;
if (isAsleep == true) {
System.out.println("Animal's constructor invoked");
} else {
System.out.println("constructor invoked - my new animal is awake");
}
}
public Animal(boolean asleep) {
isAsleep = asleep;
System.out.println("Animal's constructor WITH ASLEEP invoked");
}
public Animal(String n) {
this.name = n;
}
// properties
private String name;
private int numberOfLegs;
public int numberOfEyes;
public boolean isAsleep;
// methods
public void eat() {
System.out.println(name + ":has eaten");
}
public void sleep() {
System.out.println(name + ":is sleeping");
isAsleep = true;
}
public void wakeUp() {
System.out.println(name + ":wakes up");
isAsleep = false;
}
// getters and setters
public String getName() {
return this.name;
}
public void setName(String n) {
this.name = n;
}
public int getNumOfLegs() {
System.out.println(name + ":getting number of legs value");
return numberOfLegs;
}
public void setNumOfLegs(int num) {
System.out.println("setting number of legs for this animal instance");
System.out.println("old value of legs for " + name+ ": " + numberOfLegs);
this.numberOfLegs = num;
System.out.println("new value of legs for " + name+ ": " + numberOfLegs);
}
}