-
Notifications
You must be signed in to change notification settings - Fork 1
/
Family.java
125 lines (111 loc) · 2.34 KB
/
Family.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
import java.util.ArrayList;
/**
* <h1>Family Object</h1>
* Object to store a representation of a person in the tree.
* @author argonboron - Corrie McGregor
* @version 1.0
* @since 2018-12-23
*/
public class Family {
private int year;
private int id;
private boolean marriage;
private ArrayList<Person> children = new ArrayList<>();
private ArrayList<Person> parents = new ArrayList<>();
/**
* Prints out the family details.
*/
public void printFamily() {
System.out.print("Parents: ");
for (Person parent : parents) {
System.out.print(parent.getName() + ", ");
}
System.out.println();
System.out.println("Children: ");
for (Person aChildren : children) {
System.out.println("----" + aChildren.getName());
}
System.out.println("Year Adopted: " + year);
System.out.println("Parents Married? " + marriage);
}
/**
* Getter.
* @return the year the family was formed.
*/
int getYear() {
return year;
}
/**
* Add parent to family.
* @param parent the parent.
*/
void addParent(Person parent) {
parents.add(parent);
}
/**
* Return all members of this family.
* @return All members of the family.
*/
ArrayList<Person> getAllMembers() {
ArrayList<Person> all = new ArrayList<>();
all.addAll(parents);
all.addAll(children);
return all;
}
/**
* Getter.
* @return if the parents of this family are married.
*/
boolean hasMarriage() {
return marriage;
}
/**
* Getter.
* @return The children in this family.
*/
ArrayList<Person> getChildren() {
return children;
}
/**
* Set the marriage to true and adds all parents to each others spouses list.
*/
void setMarriage() {
marriage = true;
}
/**
* Getter.
* @return The id of this family.
*/
int getID() {
return id;
}
/**
* Getter.
* @return The children in this family.
*/
ArrayList<Person> getParents() {
return parents;
}
/**
* Add a new child to the family.
* @param child the child.
*/
void addChild(Person child) {
children.add(child);
}
/**
* Setter.
* @param year year the family was formed.
*/
void setYear(int year) {
this.year = year;
}
/**
* Constructor.
* @param id the id of the family.
*/
Family(int id){
this.id = id;
marriage = false;
}
}