-
Notifications
You must be signed in to change notification settings - Fork 6
/
Animal.java
128 lines (113 loc) · 2.77 KB
/
Animal.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Abstract class Animal
*
* @author Mr. Jaffe
* @version 1.0 2017-07-13
*/
public abstract class Animal
{
// instance variables - replace the example below with your own
private String color;
private int legs;
private String studentName;
/**
* Constructor
*/
public Animal()
{
this("Unknown student", "Colorless", 4); // Default is a black animal with 4 legs
}
/**
* Overloaded constructor that sets color and # of legs
*
* @param color Initial color
* @param legs Initial # of legs
*/
public Animal(String studentName, String color, int legs) {
this.studentName = studentName;
this.color = color;
this.legs = legs;
}
/**
* Getter for color
*/
public String getColor() {
return this.color;
}
/**
* Setter for color
*
* @param color New color
*/
public void setColor(String color) {
this.color = color;
}
/**
* Getter for legs
*/
public int getLegs() {
return this.legs;
}
/**
* Setter for legs
*
* @param legs New number of legs
*/
public void setLegs(int legs) {
this.legs = legs;
}
/**
* Getter for studentName
*
* @return The student name
*/
public String getStudentName() {
return this.studentName;
}
/**
* What does the animal say? Descendant classes should override this
* method or default speak will generate "Yaba-daba-doo"
*/
public String speak() {
return "Yaba-daba-doo";
}
/**
* This will return a String that describes the animal's general disposition.
* Sample dispositions could be "mean" or "friendly". Use different adjectives
* in your method. The default disposition is "meh"
*
* @return Disposition
*/
public String getDisposition() {
return "meh";
}
/**
* This will return the type of animal (i.e. "Dog", "Cat", etc)
*
* @return The type of the animal
*/
public String getType() {
return "Abstract animal";
}
/**
* This will return the animal's name. What's the default name?
*
* @return The name of the animal (i.e. "Fido", "Rover")
*/
public String getName() {
return "No name defined - bummer";
}
/**
* toString() is a method that all Java classes implement. It's where you can
* generate a string that describes the object. You should not override this
* method unless you know what you're doing
*/
@Override
public String toString() {
StringBuffer buffer = new StringBuffer("");
buffer.append("It is a "+this.getType()+"\n");
buffer.append("Its name is "+this.getName()+", it is "+this.getColor()+" with "+this.getLegs()+" legs\n");
buffer.append("Its disposition is "+this.getDisposition()+" and it says "+this.speak()+"\n");
return buffer.toString();
}
}