-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx1.java
More file actions
82 lines (63 loc) · 1.92 KB
/
Ex1.java
File metadata and controls
82 lines (63 loc) · 1.92 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
/**
* This class reads the xml file's name and all queries from the input file and prints results into the output file.
* @author Maya
*
*/
public class Ex1 {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
// Open the input file for reading
try (BufferedReader reader = new BufferedReader(new FileReader("input.txt"))){
BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
String xml = reader.readLine();
readXmlFile x = new readXmlFile(xml);
String line;
while ((line = reader.readLine()) != null) {
String input = line;
//System.out.println(input);
String query [] = input.split(",");
int algoNum = Integer.parseInt(query[query.length-1]);
switch (algoNum) {
case 1:
{
bayesianNetwork bn = new bayesianNetwork(x);
String answer = FirstAlgorithmBayesianNetwork.finalCalculation(input, bn);
//System.out.println(answer);
writer.write(answer + "\n");
break;
}
case 2:
{
bayesianNetwork bn = new bayesianNetwork(x);
String answer = SecondAlgorithm.getProbability(input, bn);
//System.out.println(answer);
writer.write(answer + "\n");
break;
}
case 3:
{
bayesianNetwork bn = new bayesianNetwork(x);
String answer = ThirdAlgorithm.getProbability(input, bn);
//System.out.println(answer);
writer.write(answer + "\n");
break;
}
}
}
writer.close();
}
catch (IOException e) {
System.out.println("There's an error.\n");
e.printStackTrace();
// Handle any errors
}
}
}