-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathPet.java
More file actions
44 lines (30 loc) · 973 Bytes
/
Pet.java
File metadata and controls
44 lines (30 loc) · 973 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
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.zipcoder.pets;
abstract public class Pet implements PetBehavior, Comparable<Pet> {
private String name;
public Pet(String aName) {
this.name = aName;
}
public String speak() {
return null;
}
public String getName() {
return this.name;
}
public void setName(String aName) {
this.name = aName;
}
@Override
public int compareTo(Pet anotherPet) {
String otherPetName = anotherPet.getName();
int result = -(otherPetName.compareTo(name));
boolean sameName = (result == 0);
if (sameName) {
Class otherPetClass = anotherPet.getClass();
String otherPetClassName = otherPetClass.getSimpleName();
Class thisPetClass = this.getClass();
String thisPetClassName = thisPetClass.getSimpleName();
result = -(otherPetClassName.compareTo(thisPetClassName));
}
return result;
}
}