-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountManager.java
More file actions
76 lines (69 loc) · 2.52 KB
/
AccountManager.java
File metadata and controls
76 lines (69 loc) · 2.52 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package basicpwmanager;
import basicpwmanager.models.ACC_TYPE;
import basicpwmanager.models.Account;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Pattern;
/**
*
* @author HD
*/
public class AccountManager {
private static List<String> AccountDetails;
// private static Account AccountObj;
//TODO: Add frequently used user/pw/email
/**
* Calls for query from user input in order to get the account details.
*
* @return AccountDetails from AccountManager.CheckAccountDetails(). If '-1' is inputted, returns null.
*/
public static List<String> setAccountDetails() {
AccountDetails = new ArrayList();
//flushes the null object
Util.sc.nextLine();
for (ACC_TYPE accountQuery : ACC_TYPE.values()) {
System.out.println(accountQuery.toQuery());
String input = Util.sc.nextLine();
if (input.equals("-1")) {
return null;
} else {
AccountManager.AccountDetails.add(input);
}
}
return AccountManager.CheckAccountDetails();
}
/**
* Account Details checker which requires user to manually see if they have entered the right information.
*
* @return AccountDetails private variable
*/
public static List<String> CheckAccountDetails() {
System.out.println("Please check if the details are correct:");
Iterator<String> accountItr = AccountDetails.iterator();
Util.AccountStoringFormatKeyResetItr();
while (accountItr.hasNext()) {
System.out.println(Util.AccountStoringFormatKeyItr.next() + ": " + accountItr.next());
}
System.out.println("Are they correct? [Y]es [N]o");
String option = Util.sc.next();
boolean yesOption = Pattern.matches("([yY])|([yY][eE][sS])", option);
boolean noOption = Pattern.matches("([nN])|([nN][oO])", option);
if (yesOption) {
System.out.println("Thank you.");
return AccountDetails;
} else if (noOption) {
System.out.println("No? so sad.");
AccountManager.setAccountDetails();
} else {
System.out.println("Please enter the right option.");
AccountManager.CheckAccountDetails();
}
return null;
}
}