Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Students/Gohonel/.changeMe!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IM SO CHANGED
32 changes: 32 additions & 0 deletions Students/Gohonel/FirstAssignement - improved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Assignements;

import java.util.Scanner;

public class FirstAssignment {
public static void main(String[] args)
{
System.out.print("Enter up to where we go: ");
Scanner scan = new Scanner(System.in);
int i, j, sum = 0, a = 0, b = 0, c = 0, s = 0, n = 0;

i = scan.nextInt();

n = i / 3;

a = ( 3 * n * ( n + 1 ))/2;

n = i / 5;

b = ( 5 * n * ( n + 1 ))/2;

n = i / 15;

c = ( 15 * n * ( n + 1 ))/2;

s = a + b - c;


System.out.print("You number is: ");
System.out.println(s);
}
}
60 changes: 60 additions & 0 deletions Students/Gohonel/SecondWeek--/Functions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package Assignements;

import java.util.Arrays;

public class Functions {

public String Add(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int [100];
n = (n > m) ? n : m;
for (int i = 0; i < n; i++) {
pol[i] = pol1[i] + pol2[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Subtract(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int[100];
n = (n > m) ? n : m;
for (int i = 0; i < n; i++) {
pol[i] = pol1[i] - pol2[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Multiply(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int[100];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
pol[i + j] = (pol1[i] * pol2[j]) + pol[i + j];
}
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String MultScal(int[] pol1, int m, int scalar) {
int[] pol = new int[100];
for (int i = 0; i < m; i++) {
pol[i] = scalar * pol1[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Eval(int[] pol1, int m, int value) {
int sum = 0;
for (int i = 0; i < m; i++) {
sum = (int) (sum + (pol1[i] * (Math.pow(value, i))));
}
String p = "";
p = Integer.toString(sum);
return p;
}
}
49 changes: 49 additions & 0 deletions Students/Gohonel/SecondWeek--/InOut.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package Assignements;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

public class InOut {

public String[] read() {
BufferedReader br = null;
String[] all = new String[100];
int i = 0;
try {
br = new BufferedReader(new FileReader("C:/Users/Goron/workspace/SecondChapter/Poly.txt"));

while (i < 100) {
all[i] = br.readLine();
i++;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return all;
}

public void write(String[] out, int k, String[] text) throws FileNotFoundException, UnsupportedEncodingException {
int i = 0;

PrintWriter writer = new PrintWriter("Results.txt", "UTF-8");



for (i = 0; i < k; i++) {
writer.println(out[i]);
writer.println();
}
writer.close();
}
}
10 changes: 10 additions & 0 deletions Students/Gohonel/SecondWeek--/Poly.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
5 -4 2 0 -2 3 0 3 -17
4 -2 0 1

ADD
SUBTRACT
MULTIPLY
MUL_SCAL 4
EVAL 5
EVAL 2
EVAL 9
95 changes: 95 additions & 0 deletions Students/Gohonel/SecondWeek--/Polynomial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package Assignements;

import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Polynomial {

public static int nAll = 0;
public static int mAll = 0;

public static int[] sepInt(String[] all, int row) {
int[] pol = new int[100];
String temp = all[row];
int i = 0;
Scanner s = new Scanner(temp);

int n = temp.length() - temp.replaceAll(" ", "").length() + 1;

while (i < n) {
pol[i] = s.nextInt();
i++;
}
nAll = n;
return pol;
}

public static int[] inverse(int[] pol, int m) {
int[] ipol = new int[100];
for (int i = 0; i <= m; i++) {
ipol[i] = pol[m - i];
}
return ipol;
}

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
int i;
int[] polynom1 = new int[100];
int[] polynom2 = new int[100];


Functions F = new Functions();
InOut IO = new InOut();

String[] textFile = IO.read();
String[] sendOut = new String[100];
String tempString = null;

polynom1 = sepInt(textFile, 0);
mAll = nAll;
polynom2 = sepInt(textFile, 1);

polynom1 = inverse(polynom1, mAll);
for (i = 0; i < mAll; i++)
polynom1[i] = polynom1[i + 1];

polynom2 = inverse(polynom2, nAll);
for (i = 0; i < mAll; i++)
polynom2[i] = polynom2[i + 1];

i = 3;

while (textFile[i] != null) {
if (textFile[i].startsWith("A")) {

tempString = F.Add(polynom1, polynom2, mAll, nAll);

} else if (textFile[i].startsWith("S")) {

tempString = F.Subtract(polynom1, polynom2, mAll, nAll);

} else if (textFile[i].startsWith("M") && textFile[i].matches(".*\\d+.*") == false) {

tempString = F.Multiply(polynom1, polynom2, mAll, nAll);

} else if (textFile[i].startsWith("M") && textFile[i].matches(".*\\d+.*") == true) {

tempString = new String(F.MultScal(polynom1, mAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", "")))
+" "+ F.MultScal(polynom2, nAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", ""))));

} else if (textFile[i].startsWith("E")) {

tempString = new String(F.Eval(polynom1, mAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", "")))
+" "+ F.Eval(polynom2, nAll, Integer.parseInt(textFile[i].replaceAll("[\\D]", ""))));

}
sendOut[i-3] = new String(tempString);
i++;
}
IO.write(sendOut, i-3, textFile);

}
}

14 changes: 14 additions & 0 deletions Students/Gohonel/SecondWeek--/Results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[-16, 3, -2, 7, -2, 0,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [4, 0, -8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

1670998 451

877 25

197153686 2755

60 changes: 60 additions & 0 deletions Students/Gohonel/SecondWeek-/Functions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package Assignements;

import java.util.Arrays;

public class Functions {

public String Add(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int [100];
n = (n > m) ? n : m;
for (int i = 0; i < n; i++) {
pol[i] = pol1[i] + pol2[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Subtract(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int[100];
n = (n > m) ? n : m;
for (int i = 0; i < n; i++) {
pol[i] = pol1[i] - pol2[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Multiply(int[] pol1, int[] pol2, int m, int n) {
int[] pol = new int[100];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
pol[i + j] = (pol1[i] * pol2[j]) + pol[i + j];
}
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String MultScal(int[] pol1, int m, int scalar) {
int[] pol = new int[100];
for (int i = 0; i < m; i++) {
pol[i] = scalar * pol1[i];
}
String p = "";
p = Arrays.toString(pol);
return p;
}

public String Eval(int[] pol1, int m, int value) {
int sum = 0;
for (int i = 0; i < m; i++) {
sum = (int) (sum + (pol1[i] * (Math.pow(value, i))));
}
String p = "";
p = Integer.toString(sum);
return p;
}
}
49 changes: 49 additions & 0 deletions Students/Gohonel/SecondWeek-/InOut.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package Assignements;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

public class InOut {

public String[] read() {
BufferedReader br = null;
String[] all = new String[100];
int i = 0;
try {
br = new BufferedReader(new FileReader("C:/Users/Goron/workspace/SecondChapter/Poly.txt"));

while (i < 100) {
all[i] = br.readLine();
i++;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return all;
}

public void write(String[] out, int k, String[] text) throws FileNotFoundException, UnsupportedEncodingException {
int i = 0;

PrintWriter writer = new PrintWriter("Results.txt", "UTF-8");



for (i = 0; i < k; i++) {
writer.println(out[i]);
writer.println();
}
writer.close();
}
}
10 changes: 10 additions & 0 deletions Students/Gohonel/SecondWeek-/Poly.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
5 -4 2 0 -2 3 0 3 -17
4 -2 0 1

ADD
SUBTRACT
MULTIPLY
MUL_SCAL 4
EVAL 5
EVAL 2
EVAL 9
Loading