-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserInfo.java
220 lines (166 loc) · 6.88 KB
/
UserInfo.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
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
import java.util.Scanner;
public class UserInfo {
private String userID;
private Name name;
private String email;
private String phoneNumber;
private String password;
private boolean frozen = false;
public UserInfo(String userID, Name name, String email, String phoneNumber, String password) {
this.userID = userID;
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
this.password = password;
}
public String getUserID() {
return userID;
}
public Name getName() {
return name;
}
public String getEmail() {
return email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getPassword() {
return password;
}
public boolean getFrozen() {
return frozen;
}
public void setUserID(String userID) {
this.userID = userID;
}
public void setName(Name name) {
this.name = name;
}
public void setEmail(String email) {
this.email = email;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void setPassword(String password) {
this.password = password;
}
public void setFrozen(boolean frozen) {
this.frozen = frozen;
}
public String toString() {
return "\t\t\t\t\tUser ID : " + userID +
"\n\t\t\t\t\tName : " + name +
"\n\t\t\t\t\tEmail : " + email +
"\n\t\t\t\t\tPhone Number : " + phoneNumber;
}
int editChoiceCode(String choiceString, int maxChoice) {
int primeNumber = 1, indexLoop = 0;
char choiceChar;
do {
try {
choiceChar = choiceString.charAt(indexLoop);
} catch (Exception exception) {
return 0;
}
if (choiceChar == '1' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 2;
else if (choiceChar == '2' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 3;
else if (choiceChar == '3' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 5;
else if (choiceChar == '4' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 7;
else if (choiceChar == '5' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 11;
else if (choiceChar == '6' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 13;
else if (choiceChar == '7' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 17;
else if (choiceChar == '8' && maxChoice >= Character.getNumericValue(choiceChar)) primeNumber *= 19;
else primeNumber = 0;
if (primeNumber == 0) break;
indexLoop += 2;
// 6 5
} while (indexLoop <= choiceString.length());
return primeNumber;
}
public static Name inputName(String firstNameQuestion, String lastNameQuestion) {
Scanner scanner = new Scanner(System.in);
boolean validation = true;
String firstName, lastName;
do {
if (!validation) System.out.println("\n\t\t\t\t\tInvalid format, please try again!");
System.out.print(firstNameQuestion);
firstName = scanner.nextLine().trim();
System.out.print(lastNameQuestion);
lastName = scanner.nextLine().trim();
try {
for (int loop = 0; loop < firstName.length(); loop++) {
if (Character.isAlphabetic(firstName.charAt(loop)) || firstName.charAt(loop) == ' ' || firstName.charAt(loop) == '/') {
validation = true;
} else {
validation = false;
break;
}
}
if (validation) {
for (int loop = 0; loop < lastName.length(); loop++) {
if (Character.isAlphabetic(lastName.charAt(loop)) || lastName.charAt(loop) == ' ' || lastName.charAt(loop) == '/') {
validation = true;
} else {
validation = false;
break;
}
}
}
} catch (Exception exception) {
System.out.println("\t\t\t\t\tEnter the name!");
validation = false;
}
} while (!validation);
return new Name(firstName, lastName);
}
public static String inputEmail(String question) {
Scanner scanner = new Scanner(System.in);
boolean validation = true;
String email;
do {
if (!validation) System.out.println("\n\t\t\t\t\tInvalid format, please try again!");
System.out.print(question);
email = scanner.nextLine().trim();
validation = email.contains("@") && email.contains(".com")
&& email.charAt(0) != '@' && email.charAt(0) != '.';
} while (!validation);
return email;
}
public static String inputPhoneNumber(String question) {
Scanner scanner = new Scanner(System.in);
boolean validation = true;
String phoneNumber;
do {
if (!validation) System.out.println("\n\t\t\t\t\tInvalid format, please try again!");
System.out.print(question);
phoneNumber = scanner.nextLine().trim();
if ((phoneNumber.length() == 10 || phoneNumber.length() == 11) &&
phoneNumber.charAt(0) == '0' && phoneNumber.charAt(1) == '1') {
for (int loop = 0; loop < phoneNumber.length(); loop++) {
if (Character.isDigit(phoneNumber.charAt(loop))) {
validation = true;
} else {
validation = false;
break;
}
}
} else validation = false;
} while (!validation);
return phoneNumber;
}
public static boolean validPassword(String password) {
//consist of numeric, upper and lowercase alphabet, length >= 8
boolean numeric = false, uppercase = false, lowercase = false;
if (password.length() <= 6) return false;
for (int loop = 0; loop < password.length(); loop++) {
if (!numeric) if (Character.isDigit(password.charAt(loop))) numeric = true;
if (Character.isAlphabetic(password.charAt(loop))) {
if (!uppercase && Character.isUpperCase(password.charAt(loop))) uppercase = true;
if (!lowercase && Character.isLowerCase(password.charAt(loop))) lowercase = true;
}
}
return numeric && uppercase && lowercase;
}
}