-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
163 lines (119 loc) · 4.59 KB
/
ReadFile.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
*/
import java.io.*;
public class ReadFile {
private int inputs;
private int size;
/** ReadFile Constructor.
*
* @param inputs - total number of ticket inputs per customer
* @param size - total number of customers
*/
public ReadFile(int inputs, int size){
this.inputs = inputs;
this.size = size;
}
/** Returns the number of customer inputs
*
* @return number of inputs
*/
public int GetInputs(){
return this.inputs;
}
/** Returns the number of customers
*
* @return number of customers
*/
public int GetSize(){
return this.size;
}
/** Sets a new number of customer inputs
*
* @param inputs - sets new number of inputs
*/
public void SetInputs(int inputs){
this.inputs = inputs;
}
/** Sets a new number of customers
*
* @param size - sets new number of customers
*/
public void SetSize(int size){
this.size = size;
}
/** Scans the file, customer index is row, customer order info is col
*
* @return the correct inputs in a 2d array
*/
public String[][] ScanFile(){
String line;
ErrorLog log = new ErrorLog();
String[][] results = new String[1][1];
// Reads the file (values.txt) and stores the entries in an Array
try{
BufferedReader in = new BufferedReader(new FileReader("Values.txt"));
line = in.readLine();
String correctLine;
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 (NumberFormatException e) {
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 = new String [this.size][(this.inputs)];
// Reads the file and stores values in an array
while (line != null){
for (int l = 0; l < this.size; l++){
for (int q = 0; q < this.inputs; q++){
line = in.readLine();
if (line == null){
in.close();
return results;
}
if (q % 3 == 0){
// Try's to change input from string to int
try {
int test = Integer.parseInt(line);
int lineError = (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 (NumberFormatException e){
// input length must be > 3 as the lowest length of an email is 3 characters
if (line.length() < 3){
int lineError = (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();
return results;
// Invalid entry
} catch (IOException iox){
System.out.println("Invalid entry");
}
return (results);
}
}