Didn't manage to finish the output · JavaSummer/JavaMainRepo@f00a134 · GitHub
Skip to content

Commit f00a134

Browse files
committed
Didn't manage to finish the output
1 parent 5303044 commit f00a134

5 files changed

Lines changed: 228 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package Assignements;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.io.PrintWriter;
8+
import java.io.UnsupportedEncodingException;
9+
10+
public class InOut {
11+
12+
public String[] read() {
13+
BufferedReader br = null;
14+
String[] all = new String[100];
15+
int i = 0;
16+
try {
17+
br = new BufferedReader(new FileReader("C:/Users/Goron/workspace/SecondChapter/Poly.txt"));
18+
19+
while (i < 100) {
20+
all[i] = br.readLine();
21+
i++;
22+
}
23+
} catch (IOException e) {
24+
e.printStackTrace();
25+
} finally {
26+
try {
27+
if (br != null)
28+
br.close();
29+
} catch (IOException ex) {
30+
ex.printStackTrace();
31+
}
32+
}
33+
return all;
34+
}
35+
36+
public void write(String[] out, int k, String[] text) throws FileNotFoundException, UnsupportedEncodingException {
37+
int i = 0;
38+
39+
PrintWriter writer = new PrintWriter("Results.txt", "UTF-8");
40+
41+
42+
43+
for (i = 0; i < k; i++) {
44+
writer.println(out[i]);
45+
writer.println();
46+
}
47+
writer.close();
48+
}
49+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
5 -4 2 0 -2 3 0 3 -17
2+
4 -2 0 1
3+
4+
ADD
5+
SUBTRACT
6+
MULTIPLY
7+
MUL_SCAL 4
8+
EVAL 5
9+
EVAL 2
10+
EVAL 9
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package Assignements;
2+
3+
import java.util.Scanner;
4+
import java.io.FileNotFoundException;
5+
import java.io.UnsupportedEncodingException;
6+
import java.util.Arrays;
7+
8+
public class Polynomial {
9+
10+
public static int nAll = 0;
11+
public static int mAll = 0;
12+
13+
public static int[] sepInt(String[] all, int row) {
14+
int[] pol = new int[100];
15+
String temp = all[row];
16+
int i = 0;
17+
Scanner s = new Scanner(temp);
18+
19+
int n = temp.length() - temp.replaceAll(" ", "").length() + 1;
20+
21+
while (i < n) {
22+
pol[i] = s.nextInt();
23+
i++;
24+
}
25+
nAll = n;
26+
return pol;
27+
}
28+
29+
public static int[] inverse(int[] pol, int m) {
30+
int[] ipol = new int[100];
31+
for (int i = 0; i <= m; i++) {
32+
ipol[i] = pol[m - i];
33+
}
34+
return ipol;
35+
}
36+
37+
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
38+
int i;
39+
int[] polynom1 = new int[100];
40+
int[] polynom2 = new int[100];
41+
42+
43+
Functions F = new Functions();
44+
InOut IO = new InOut();
45+
46+
String[] textFile = IO.read();
47+
String[] sendOut = new String[100];
48+
String tempString = null;
49+
50+
polynom1 = sepInt(textFile, 0);
51+
mAll = nAll;
52+
polynom2 = sepInt(textFile, 1);
53+
54+
polynom1 = inverse(polynom1, mAll);
55+
for (i = 0; i < mAll; i++)
56+
polynom1[i] = polynom1[i + 1];
57+
58+
polynom2 = inverse(polynom2, nAll);
59+
for (i = 0; i < mAll; i++)
60+
polynom2[i] = polynom2[i + 1];
61+
62+
i = 3;
63+
64+
while (textFile[i] != null) {
65+
if (textFile[i].startsWith("A")) {
66+
67+
tempString = F.Add(polynom1, polynom2, mAll, nAll);
68+
69+
} else if (textFile[i].startsWith("S")) {
70+
71+
tempString = F.Subtract(polynom1, polynom2, mAll, nAll);
72+
73+
} else if (textFile[i].startsWith("M") && textFile[i].matches(".*\\d+.*") == false) {
74+
75+
tempString = F.Multiply(polynom1, polynom2, mAll, nAll);
76+
77+
} else if (textFile[i].startsWith("M") && textFile[i].matches(".*\\d+.*") == true) {
78+
79+
tempString = new String(F.MultScal(polynom1, mAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", "")))
80+
+" "+ F.MultScal(polynom2, nAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", ""))));
81+
82+
} else if (textFile[i].startsWith("E")) {
83+
84+
tempString = new String(F.Eval(polynom1, mAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", "")))
85+
+" "+ F.Eval(polynom2, nAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", ""))));
86+
87+
}
88+
sendOut[i-3] = new String(tempString);
89+
i++;
90+
}
91+
IO.write(sendOut, i-3, textFile);
92+
93+
}
94+
}
95+
Lines changed: 14 additions & 0 deletions

0 commit comments

Comments
 (0)