- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
Latest commit
163 lines (119 loc) · 4.59 KB
/
Copy pathReadFile.java
File metadata and controls
163 lines (119 loc) · 4.59 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
152
153
154
155
156
157
158
159
160
161
162
163
/**Reads input file
*
* ReadFile Class
* @author Danny Guan
* @version 9
*/
importjava.io.*;
publicclassReadFile {
privateintinputs;
privateintsize;
/** ReadFile Constructor.
*
* @param inputs - total number of ticket inputs per customer
* @param size - total number of customers
*/
publicReadFile(intinputs, intsize){
this.inputs = inputs;
this.size = size;
}
/** Returns the number of customer inputs
*
* @return number of inputs
*/
publicintGetInputs(){
returnthis.inputs;
}
/** Returns the number of customers
*
* @return number of customers
*/
publicintGetSize(){
returnthis.size;
}
/** Sets a new number of customer inputs
*
* @param inputs - sets new number of inputs
*/
publicvoidSetInputs(intinputs){
this.inputs = inputs;
}
/** Sets a new number of customers
*
* @param size - sets new number of customers
*/
publicvoidSetSize(intsize){
this.size = size;
}
/** Scans the file, customer index is row, customer order info is col
*
* @return the correct inputs in a 2d array
*/
publicString[][] ScanFile(){
Stringline;
ErrorLoglog = newErrorLog();
String[][] results = newString[1][1];
// Reads the file (values.txt) and stores the entries in an Array
try{
BufferedReaderin = newBufferedReader(newFileReader("Values.txt"));
line = in.readLine();
StringcorrectLine;
try {
this.size = Integer.parseInt(line);
if (this.size == 0){
System.out.println("There are no ticket requests");
log.OutputLog("No Requests", "", 1);
System.exit(0);
}
} catch (NumberFormatExceptione) {
System.out.println("Input error, no inputs");
System.out.println("Input error on line 1, integer expected, received: " + line);
log.OutputLog("No inputs", line, 1);
System.exit(0);
}
results = newString [this.size][(this.inputs)];
// Reads the file and stores values in an array
while (line != null){
for (intl = 0; l < this.size; l++){
for (intq = 0; q < this.inputs; q++){
line = in.readLine();
if (line == null){
in.close();
returnresults;
}
if (q % 3 == 0){
// Try's to change input from string to int
try {
inttest = Integer.parseInt(line);
intlineError = (l * this.inputs) + 2;
System.out.println("Input error, wrong input type");
System.out.println("Input error on line: " + lineError + ", email expected, received: " + line);
log.OutputLog("Wrong Input type", line, lineError);
System.exit(0);
// If exception thrown means correct input received
} catch (NumberFormatExceptione){
// input length must be > 3 as the lowest length of an email is 3 characters
if (line.length() < 3){
intlineError = (l * this.inputs) + 2;
System.out.println("Input error, input size");
System.out.println("Input error on line: " + lineError + ", email expected, received: " + line);
log.OutputLog("Wrong Input size", line, lineError);
System.exit(0);
}
}
}
// If the input's correct, the input will be passed through
correctLine = line;
results[l][q] = correctLine;
}
}
}
in.close();
returnresults;
// Invalid entry
} catch (IOExceptioniox){
System.out.println("Invalid entry");
}
return (results);
}
}