-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowFriendRequests.java
179 lines (129 loc) · 6.04 KB
/
ShowFriendRequests.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
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class ShowFriendRequests
{
Scanner sc = new Scanner(System.in);
Scanner s = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Account account = null;
// To check whether already friends or not
public boolean isMyFriend(Account a)
{
// If list is empty
if (Login.currentLoginAccount.getFriends() == null)
return false;
for (Account b : Login.currentLoginAccount.getFriends() )
{
if (a.hashCode() == b.hashCode())
return true;
}
return false;
}
// To check Pending Friend Requests
public void showFriendRequests() throws IOException
{
MainPage.clearScreen(); // Clear Screen
// Object of SendRequest Class
SendRequest obj = new SendRequest();
// Object of FriendRequestList Class
FriendRequestsList list = new FriendRequestsList();
int choice;
// Confirm or Delete the Request
do
{
list.friendRequestsList();
System.out.println("\n\n\n\t\t\t1. Confirm Request\n");
System.out.println("\t\t\t2. Delete Request");
System.out.println("\n\n\t\t\tIf No Friends Available or to Return Press 0.");
System.out.print("\n\n\t\t\tEnter Choice: ");
choice = sc.nextInt();
// To Confirm Request
if(choice == 1)
{
MainPage.clearScreen(); // Clear Screen
// Input Username of the account to Confirm Request
System.out.println("\n\n\t\t\t----------------------------------");
System.out.print("\t\t\t Enter Username: ");
String name = br.readLine();
System.out.println("\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
// Find Account
account = obj.findAccountByName(name);
// If Account does not exist
if (account == null) {
System.out.println("\n\n\t\t\t-----------------------------");
System.out.println("\n\t\t\t User Not Found!");
System.out.println("\n\t\t\t-----------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
return;
}
System.out.println("\n\n\t\t\t----------------------------------");
System.out.println("\t\t\t " + account.getName() + " Found");
System.out.println("\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Confirm " + account.getName() + ".... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
// Add Account
Login.currentLoginAccount.addFriend(account);
System.out.println("\n\n\t\t\t----------------------------------");
System.out.println("\n\t\t\t Friend Request CONFIRMED!");
System.out.println("\n\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
}
// To Delete the Request
else if (choice == 2)
{
MainPage.clearScreen(); // Clear Screen
System.out.println("\n\n\t\t\t----------------------------------");
System.out.print("\t\t\t Enter Username: ");
String name = br.readLine();
System.out.println("\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
// Find Account
account = obj.findAccountByName(name);
// If Account does not exist
if (account == null)
{
System.out.println("\n\n\t\t\t-----------------------------");
System.out.println("\n\t\t\t User Not Found!");
System.out.println("\n\t\t\t-----------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
continue;
}
// Remove Account
account.removeFriend(Login.currentLoginAccount);
System.out.println("\n\n\t\t\t----------------------------------");
System.out.println("\n\t\t\t Friend Request DELETED!");
System.out.println("\n\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
}
else if(choice != 0)
{
MainPage.clearScreen(); // Clear Screen
System.out.println("\n\n\t\t\t----------------------------------");
System.out.println("\n\t\t\t Wrong Choice!");
System.out.println("\n\t\t\t----------------------------------");
System.out.print("\n\n\n Press Enter to Continue..... ");
s.nextLine();
MainPage.clearScreen();
}
} while(choice != 0);
System.out.print("\n\n\n Press Enter and Return..... ");
s.nextLine();
MainPage.clearScreen(); // Clear Screen
}
}