-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChemValidationMain.java
More file actions
73 lines (63 loc) · 1.54 KB
/
Copy pathChemValidationMain.java
File metadata and controls
73 lines (63 loc) · 1.54 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
import java.io.*;
/**
* CS 162J - Te-Feng (Dylan) Pan
* Lab 4A: Chemistry Experiments Data Validation.
*/
public class ChemValidationMain
{
public static void dataValidation(int[][] data) throws DataNegativeException, DataMaxException
{
int[] dataMax = {35, 55, 72, 75, 45, 100};
for (int i = 0; i < data.length; i++)
{
for (int j = 0; j < data[i].length; j++)
{
if (data[i][j] < 0)
{
throw new DataNegativeException(data[i][j]);
}
if (data[i][j] > dataMax[i])
{
throw new DataMaxException(data[i][j], dataMax[i]);
}
}
}
}
public static void main(String[] args) throws IOException
{
int[][] test = new int[5][7];
boolean endOfFile = false; // End of file flag
FileInputStream fileStream = new FileInputStream("Lab4AData.dat");
DataInputStream dataStream = new DataInputStream(fileStream);
while (!endOfFile)
{
try
{
for (int i = 0; i < test.length; i++)
{
for (int j = 0; j < test[i].length; j++)
{
test[i][i] = dataStream.readInt();
}
}
}
catch (EOFException e)
{
endOfFile = true;
}
}
boolean testingData = true;
while(testingData)
{
try
{
dataValidation(test);
}
catch (ChemValidationException e)
{
System.out.println(e.getMessage());
testingData = false;
}
}
}
}