forked from kasarrine/voterproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDriver_Liam.java
More file actions
151 lines (135 loc) · 6.06 KB
/
TestDriver_Liam.java
File metadata and controls
151 lines (135 loc) · 6.06 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
import java.util.Arrays;
public class TestDriver_Liam {
public static String formatPrint(String[][] sArr) {
StringBuilder sb = new StringBuilder();
int max = sArr[0][0].length();
String[][] elec = new String[sArr.length][3];
Arrays.fill(elec[0], "");
for(int i = 1; i < sArr.length; i++) {
int temp = sArr[i][0].length();
if(max < temp) {
max = temp;
}
Arrays.fill(elec[i], "");
}
if(14 < sArr[0].length) {
elec = Candidate.getElecVotes(sArr);
}
for(int i = 0; i < sArr.length; i++) {
int[] chLen = new int[sArr[i].length - 1];
int[] temp = new int[] {max + 2, 12, 16, 16, 19, 7, 8, 7, 34, 7, 27, 20, 43, 7};
if(sArr[0].length == 4) {
temp[2] = 11;
}
for(int j = 0; j < chLen.length && j < temp.length; j++) {
chLen[j] = temp[j];
}
if(14 < chLen.length) {
System.arraycopy(temp, 0, chLen, 0, temp.length);
for(int j = 14; j < chLen.length - 1; j++) {
chLen[j] = 6;
}
chLen[chLen.length - 1] = 11;
}
for(int j = 0; j < sArr[i].length - 1; j++) {
char[] ch = new char[chLen[j] - sArr[i][j].length()];
Arrays.fill(ch, ' ');
sb.append(sArr[i][j]).append(ch);
}
if(14 < sArr[0].length) {
char[] ch = new char[9 - sArr[i][sArr[i].length - 1].length()];
Arrays.fill(ch, ' ');
sb.append(sArr[i][sArr[i].length - 1]).append(ch).append(elec[i][2]).append("\n");
} else {
sb.append(sArr[i][sArr[i].length - 1]).append("\n");
}
}
return sb.toString();
}
public static void main(String[] args) {
Candidate.loadData("TX"); //set data files
Ballot.loadData("TX");
Voter.loadData();
String[] voterInfo = new String[11]; //creates array and populates with data for registered user
String[] input = new String[] {"DOE", "JOHN", "1234 ROAD ST", "CITY", "TX", "123456", "01022003"}; //should get this from user
for(int i = 0; i < input.length; i++) {
voterInfo[i + 1] = input[i]; //voterInfo lastName is at 1
}
String searchKey = Voter.getSearchKeyNAD(voterInfo); //gets string to search with
long locInFile; //saves location in voterFile of voterInfo
if(!Voter.checkKeyNAD(searchKey)) { //if user isn't registered, gets other necessary info to register
voterInfo[8] = new String("M"); //should get this from user
voterInfo[9] = new String("W"); //should get this from user
voterInfo = Voter.register(voterInfo); //registers voter, returns complete info
locInFile = Voter.getKeyValNAD(searchKey);
} else { //otherwise overwrite user inputed info with array containing all stored info
locInFile = Voter.getKeyValNAD(searchKey);
voterInfo = Voter.lookup(locInFile);
}
System.out.println("voterInfo: " + Arrays.toString(voterInfo)); //test print
if(!Candidate.isStateValid(voterInfo[5])) { //checks if voter is registered in this state
System.out.println("STATE IS NOT VALID"); //test print
}
if(Voter.isExpired(voterInfo[10])) { //checks expiration date of second test, because the test isn't expired, it shouldn't do anything, but it has been tested previously
voterInfo = Voter.editLine(new String[] {Voter.genExpDate()}, 10, Voter.getKeyValNAD(searchKey));
System.out.println("voterInfo: " + Arrays.toString(voterInfo)); //test print
}
Candidate.addPres(new String[] {"PRESIDENT AND VICE", "REPUBLICAN", "JAMES ROBERT AND JIMMY KRISS", "DEMOCRAT", "ELISHA BERTHA AND CATHERINE KATE"});
Candidate.addPos(new String[] {"SENATOR", "REPUBLICAN", "JEREMY BENTLY", "REPUBLICAN", "HELDA CAMERON"});
int posCount = Candidate.getPosNum();
if(0 < posCount) { //checks if there are any positions to cast ballot for
System.out.println("\nchoices:");
for(int i = 1; i < (posCount + 1); i++) { //loops positions, shifted up 1
String[][] candidates = Candidate.getAllCand(i);
System.out.println(formatPrint(candidates));
System.out.println();
}
if(!Ballot.checkKey(voterInfo[0])) { //checks that voter hasn't submitted already
Ballot.submit(new int[] {1, 2}, voterInfo); //votes for position 1 candidate 1 and position 2 candidate 2
if(Ballot.checkIfBallots()) { //checks that there are ballots
String[] ballotInfo = Ballot.lookup(Ballot.getKeyVal(Voter.getVUID(locInFile))); //uses saved searchKey for testing, admin would have to look this key up using Voter.lookup()
System.out.println("ballot:" + "\n");
String[][] ballotArr = new String[ballotInfo.length - 1][3];
for(int i = 1; i < ballotInfo.length; i++) { //loops through ballot
ballotArr[i - 1] = Candidate.lookup(ballotInfo[i], i);
}
System.out.println(formatPrint(ballotArr));
if(Candidate.isPresElec()) { //checks if it is a presidential election
System.out.println("\n" + "stats: " + "\n"); //test prints demographics
String[][] presidents = Candidate.getAllPresStats();
System.out.println(formatPrint(presidents));
System.out.println();
for(int i = 2; i < (posCount + 1); i++) {
String[][] candidates = Candidate.getAllCandStats(i);
System.out.println(formatPrint(candidates));
System.out.println();
}
System.out.println("winners: " + "\n");
String[][] electorial = Candidate.getElecVotes(presidents);
System.out.println(formatPrint(electorial));
System.out.println("\n" + Candidate.getPresWin(electorial));
for(int i = 2; i < (posCount + 1); i++) {
String[][] candidates = Candidate.getAllCandStats(i);
System.out.println(Candidate.getCandWin(candidates));
}
} else {
for(int i = 1; i < (posCount + 1); i++) {
String[][] candidates = Candidate.getAllCandStats(i);
System.out.println(Arrays.toString(candidates[0]));
for(int j = 1; j < candidates.length; j++) {
System.out.println(Arrays.toString(candidates[j]));
}
System.out.println();
}
for(int i = 1; i < (posCount + 1); i++) {
String[][] candidates = Candidate.getAllCandStats(i);
System.out.println("\t" + Candidate.getCandWin(candidates));
System.out.println();
}
}
}
}
}
Candidate.clear(); //clears files for test so upon restart, candidates aren't readded
}
}