-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpn.java
42 lines (33 loc) · 956 Bytes
/
rpn.java
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
import java.util.*;
import java.io.*;
import java.nio.file.*;
public class rpn {
public ArrayList<equation> equations;
public rpn(String[] args) {
equations = new ArrayList<equation>();
try {
readFile(args[0]);
}
catch (Exception e) {
System.out.println("Error opening file!");
e.printStackTrace();
}
for (int i = 0; i < equations.size(); i++) {
System.out.println("Solution to equation [" + i + "]: " + equations.get(i).convertToRPN());
}
}
public void readFile(String filePath) throws Exception {
Path file = Paths.get(filePath);
try (InputStream in = Files.newInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String line = "";
while ((line = reader.readLine()) != null) {
equation curEquation = new equation(line);
equations.add(curEquation);
}
}
}
public static void main(String[] args) {
new rpn(args);
}
}