-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidate.java
More file actions
63 lines (62 loc) · 2 KB
/
Copy pathValidate.java
File metadata and controls
63 lines (62 loc) · 2 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
package tracker;
import java.util.ArrayList;
import java.util.List;
public class Validate {
private final List<String> rawCopy;
private List<String> lastName;
private String firstName;
private String email;
private Match match;
Validate(List<String> rawInput) {
this.rawCopy = new ArrayList<>(rawInput);
}
public String getFirstName() {
return firstName;
}
public List<String> getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
private int inputErrorChecks(){
int errorCode = 0;
if(rawCopy.size() == 1 && !rawCopy.get(0).equalsIgnoreCase("back")) {
errorCode = 101;
System.out.println("Incorrect credentials.");
} else if(rawCopy.size() < 3 ) {
errorCode = 102;
System.out.println("Incorrect credentials.");
}
return errorCode;
}
private void assign(){
int stringIndex = rawCopy.size() - 1;
firstName = rawCopy.get(0);
email = rawCopy.get(stringIndex);
rawCopy.remove(0);
stringIndex = rawCopy.size() - 1;
rawCopy.remove(stringIndex);
lastName = new ArrayList<>(rawCopy);
}
private boolean validatedResults() {
boolean results = false;
if(match.getFirstNameMatches() && match.getLastNameMatches()
&& match.getEmailMatches()) {
return true;}
if(!match.getFirstNameMatches()) System.out.println("Incorrect first name.");
else if(!match.getLastNameMatches()) System.out.println("Incorrect last name.");
else if(!match.getEmailMatches()) System.out.println("Incorrect email.");
return results;
}
public boolean run() {
int errorCode = inputErrorChecks();
if(errorCode == 0) {
assign();
match = new Match(firstName, lastName, email);
return validatedResults();
} else {
return false;
}
}
}