From 5de991dd326103647b28e7d95b92b32a9e1671b9 Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 17 Sep 2020 11:29:50 +0200 Subject: Added m5 assignments --- sem5/oop/m4/shapes/src/MyPoint.java | 44 +++++++++++++++++++++++++++++++++++ sem5/oop/m5/opg1/.classpath | 6 +++++ sem5/oop/m5/opg1/.gitignore | 1 + sem5/oop/m5/opg1/.project | 17 ++++++++++++++ sem5/oop/m5/opg1/src/Main.java | 35 ++++++++++++++++++++++++++++ sem5/oop/m5/opg2/.classpath | 6 +++++ sem5/oop/m5/opg2/.gitignore | 1 + sem5/oop/m5/opg2/.project | 17 ++++++++++++++ sem5/oop/m5/opg2/src/Main.java | 10 ++++++++ sem5/oop/m5/opg2/src/PrintThread.java | 20 ++++++++++++++++ 10 files changed, 157 insertions(+) create mode 100644 sem5/oop/m4/shapes/src/MyPoint.java create mode 100644 sem5/oop/m5/opg1/.classpath create mode 100644 sem5/oop/m5/opg1/.gitignore create mode 100644 sem5/oop/m5/opg1/.project create mode 100644 sem5/oop/m5/opg1/src/Main.java create mode 100644 sem5/oop/m5/opg2/.classpath create mode 100644 sem5/oop/m5/opg2/.gitignore create mode 100644 sem5/oop/m5/opg2/.project create mode 100644 sem5/oop/m5/opg2/src/Main.java create mode 100644 sem5/oop/m5/opg2/src/PrintThread.java diff --git a/sem5/oop/m4/shapes/src/MyPoint.java b/sem5/oop/m4/shapes/src/MyPoint.java new file mode 100644 index 0000000..46f1ffb --- /dev/null +++ b/sem5/oop/m4/shapes/src/MyPoint.java @@ -0,0 +1,44 @@ + +public class MyPoint { + private double x, y; + + public MyPoint(double x, double y) { + this.x = x; + this.y = y; + } + + public double getX() { + return this.x; + } + public double getY() { + return this.y; + } + + /** + * Subtracts two vectors, thus returning the difference. + * @param b point to subtract from this. + * @return returns a MyPoint which is actually a vector + */ + public MyPoint sub(MyPoint b) { + // This is actually a vector and not a point + return new MyPoint(this.getX() - b.getX(), this.getY() - b.getY()); + } + /** + * Returns a new MyVector with positive components + */ + public MyPoint abs() { + return new MyPoint(Math.abs(this.getX()), Math.abs(this.getY())); + } + + /** + * Calculates the length of MyPoint as if it was a vector. + * @return + */ + public double modulo() { + return Math.sqrt(this.getX() * this.getX() + this.getY() * this.getY()); + } + + public String toString() { + return String.format("[%f, %f]", this.getX(), this.getY()); + } +} diff --git a/sem5/oop/m5/opg1/.classpath b/sem5/oop/m5/opg1/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/sem5/oop/m5/opg1/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/sem5/oop/m5/opg1/.gitignore b/sem5/oop/m5/opg1/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/sem5/oop/m5/opg1/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/sem5/oop/m5/opg1/.project b/sem5/oop/m5/opg1/.project new file mode 100644 index 0000000..8c2b620 --- /dev/null +++ b/sem5/oop/m5/opg1/.project @@ -0,0 +1,17 @@ + + + mm5opg1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sem5/oop/m5/opg1/src/Main.java b/sem5/oop/m5/opg1/src/Main.java new file mode 100644 index 0000000..97f992d --- /dev/null +++ b/sem5/oop/m5/opg1/src/Main.java @@ -0,0 +1,35 @@ +import javax.swing.JOptionPane; +import javax.swing.JFrame; +import java.nio.file.Files; +import java.nio.file.Path; +import java.io.IOException; + +class PaneThing { + JFrame f; + public PaneThing(String fname) throws IOException { + String content = Files.readString(Path.of(fname)); + + + f = new JFrame(); + JOptionPane.showMessageDialog(f, content); + } +} + +public class Main { + + public static void main(String[] args) { + + String fname = "hej.txt"; + if (args.length > 0) { + fname = args[0]; + } + + try { + PaneThing pt = new PaneThing(fname); + } catch (Exception e) { + System.err.printf("error: %s%n", e); + System.exit(1); + } + } + +} diff --git a/sem5/oop/m5/opg2/.classpath b/sem5/oop/m5/opg2/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/sem5/oop/m5/opg2/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/sem5/oop/m5/opg2/.gitignore b/sem5/oop/m5/opg2/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/sem5/oop/m5/opg2/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/sem5/oop/m5/opg2/.project b/sem5/oop/m5/opg2/.project new file mode 100644 index 0000000..d5b0073 --- /dev/null +++ b/sem5/oop/m5/opg2/.project @@ -0,0 +1,17 @@ + + + mm5opg2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sem5/oop/m5/opg2/src/Main.java b/sem5/oop/m5/opg2/src/Main.java new file mode 100644 index 0000000..26b95b3 --- /dev/null +++ b/sem5/oop/m5/opg2/src/Main.java @@ -0,0 +1,10 @@ + +public class Main { + + public static void main(String[] args) { + for(int i=0;i