-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
249 lines (211 loc) · 6.96 KB
/
User.java
File metadata and controls
249 lines (211 loc) · 6.96 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package application;
import java.io.Serializable;
import java.util.*;
import java.time.LocalDate;
import java.time.Period;
public class User implements Serializable {
private String username;
private String password;
private String email;
private String phoneNumber;
private userInfo info;
private userFriends friends;
private LocalDate birthday;
private int id;
public User(String username, String password, String email, String phoneNumber, LocalDate birthdayDate, int id) {
this.username = username;
this.password = password;
this.email = email;
this.phoneNumber = phoneNumber;
this.id = id;
this.info = new userInfo();
this.friends = new userFriends();
this.birthday = birthdayDate;
}
// Getters and setters
public String getUsername() {
return username;
}
public int getId() {
return id;
}
public LocalDate getBirthday() {
return birthday;
}
public int getAge() {
if (birthday != null) {
return Period.between(birthday, LocalDate.now()).getYears();
} else {
return 0;
}
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void setBirthday(LocalDate birthday) {
this.birthday = birthday;
}
public void displayInfo() {
System.out.println("Username: " + this.username);
System.out.println("Name: " + info.getName());
System.out.println("Id: " + this.id);
System.out.println("Birthday: " + this.getBirthday());
System.out.println("Age: " + this.getAge());
System.out.println("Gender: " + info.getGender());
System.out.println("Job(s): " + info.printArraylist(info.getJobs()));
System.out.println("Hobbies: " + info.printArraylist(info.getHobbies()));
}
public void displayInfo2(User currentUser) {
System.out.println("Username: " + this.username);
System.out.println("Name: " + info.getName());
System.out.println("Id: " + this.id);
System.out.println("Birthday: " + this.getBirthday());
System.out.println("Age: " + this.getAge());
System.out.println("Gender: " + info.getGender());
System.out.println("Job(s): " + info.printArraylist(info.getJobs()));
System.out.println("Hobbies: " + info.printArraylist(info.getHobbies()));
System.out.println("Mutual friend(s): " + friends.mutualFriends(currentUser).size());
System.out.print("List of Mutual Friends: ");
for (User user: friends.mutualFriends(currentUser)) {
System.out.print(user.getUsername() + " ");
}
System.out.println("");
}
public void setInfo() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter to skip");
System.out.print("Name: ");
String name = sc.nextLine();
if (!name.isBlank()) {
info.setName(name);
}
System.out.print("Gender: ");
String gender = sc.nextLine();
if (!gender.isBlank()) {
info.setGender(gender);
}
System.out.print("Address: ");
String address = sc.nextLine();
if (!address.isBlank()) {
info.setAddress(address);
}
System.out.print("School: ");
String School = sc.nextLine();
if (!School.isBlank()) {
info.setSchool(School);
}
System.out.print("Relationship status: ");
String status = sc.nextLine();
if (!status.isBlank()) {
info.setRelationshipStatus(status);
}
System.out.print("Jobs (separate with ,): ");
String jobs = sc.nextLine();
if (!jobs.isBlank()) {
String[] job = jobs.split(",");
info.setJobs(job);
}
System.out.print("Hobbies (separate with ,): ");
String hobbies = sc.nextLine();
if (!hobbies.isBlank()) {
String[] hob = hobbies.split(",");
info.setHobbies(hob);
}
}
public void updateFriend() {
int numofFriend = friends.getFriends().size();
info.updateFriends(numofFriend);
}
public boolean isFriend(User user) {
return friends.checkifFriend(user);
}
public void addFriend(User user) {
if (!isFriend(user)) {
friends.addFriends(user);
user.friends.addFriends(this);
System.out.printf("Successfully sent a friend request to %s\n", user.getUsername());
} else {
System.out.println("Already a friend");
}
}
public void removeFriend(User user) {
if (isFriend(user)) {
removeFriend(user);
user.removeFriend(this);
updateFriend();
user.updateFriend();
System.out.printf("%s successfully removed as a friend\n", user.getUsername());
} else {
System.out.printf("%s is not your friend\n", user.getUsername());
}
}
public void seePending() {
Scanner scanner = new Scanner(System.in);
for (User user: friends.getPending()) {
System.out.println(user.getUsername());
}
System.out.println("Which user do you want to interact with?");
int toInteract = scanner.nextInt() - 1;
if (toInteract > friends.getPending().size()) {
System.out.println("Invalid index");
} else {
System.out.println("1 to accept, 2 to decline");
int action = scanner.nextInt();
switch (action) {
case 1:
acceptFriend(friends.getPending().get(toInteract));
break;
case 2:
declineFriend(friends.getPending().get(toInteract));
break;
default:
System.out.println("type 1 or 2 only");
}
}
}
public void acceptFriend(User user) {
friends.acceptFriend(user);
user.friends.acceptFriend(this);
updateFriend();
user.updateFriend();
}
public void declineFriend(User user) {
friends.declineFriend(user);
user.friends.declineFriend(this);
}
public userFriends getFriends() {
return friends;
}
public void getFriendSuggestion(ArrayList<User> UsersList) {
System.out.println("Lists of suggested friends: ");
int amount = 0;
for(User user : friends.suggestedFriends(UsersList, this)) {
System.out.println(user.getUsername() + ": " + friends.mutualFriends(user).size());
if (amount == 5) {
break;
}
amount++;
}
if (amount == 0) {
System.out.println("No suggested friends found");
}
}
}