-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
82 lines (72 loc) · 2.42 KB
/
Person.java
File metadata and controls
82 lines (72 loc) · 2.42 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
/** RandomCircularListGenerator
* @author Chase Carnaroli
*
* Each person is represented by a Person class
* The Person class tracks each person's name, group, and target
*
* INSTANCE VARIABLES
* String name // person's name
* Group group // the group that the person belongs to
* Person target // the person that comes after this person on the list
*
* METHODS
* getName() -> String // returns person's name
* getGroup() -> Group // returns person's group
* getGroupName() -> String // returns group name
* setTarget() // sets person's target
* getTarget() -> Person // returns person's target
* diffGroups(Person) -> boolean // returns true if different groups, false if same group
* diffGroups(Group) -> boolean // returns true if different groups, false if same group
* equals(Person) -> boolean // return true if same person, false if different
*/
public class Person
{
// Instance Variables
private String name;
private Group group;
private Person target;
/**
* Constructor Person class
*/
public Person(String name, Group group)
{
this.name = name;
this.group = group;
}
// post: return name
public String getName(){
return name;
}
// post: returns group
public Group getGroup(){
return group;
}
// post: returns group name
public String getGroupName(){
return group.getGroupName();
}
// post: set target
public void setTarget(Person person){
target = person;
}
// post: returns target
public Person getTarget(){
return target;
}
// post: returns true if different groups, false if same group
public boolean diffGroups(Person person){
return group.equals(person.getGroup());
}
// post: returns true if different groups, false if same group
public boolean diffGroups(Group groupName){
return group.equals(groupName);
}
// post: return true if same object, false if different
public boolean equals(Person person){
return this.name == person.getName();
}
// post: return String of the person's name
public String toString(){
return name;
}
}