diff --git a/Personal/SimpleOOPExample/src/Coords.java b/Personal/SimpleOOPExample/src/Coords.java new file mode 100644 index 0000000..2f594f4 --- /dev/null +++ b/Personal/SimpleOOPExample/src/Coords.java @@ -0,0 +1,25 @@ +public class Coords { + private int x; + private int y; + + public Coords(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } +} diff --git a/Personal/SimpleOOPExample/src/Line.java b/Personal/SimpleOOPExample/src/Line.java new file mode 100644 index 0000000..d8c233f --- /dev/null +++ b/Personal/SimpleOOPExample/src/Line.java @@ -0,0 +1,45 @@ +public class Line { + private double gradient; + private double intercept; + + private int x1; + private int x2; + private int y1; + private int y2; + + public Line(Coords coords1, Coords coords2) { + this.x1 = coords1.getX(); + this.y1 = coords1.getY(); + this.x2 = coords2.getX(); + this.y2 = coords2.getY(); + } + + public void calculateGradient() { + gradient = (y2 - y1) / (x2 - x1); + } + + public void calculateIntercept() { + intercept = y1 - (gradient * x1); + } + + public void displayEquation() { + System.out.println("y = " + gradient + "x + " + intercept); + } + + public double getGradient() { + return gradient; + } + + public void setGradient(int gradient) { + this.gradient = gradient; + } + + public double getIntercept() { + return intercept; + } + + public void setIntercept(int intercept) { + this.intercept = intercept; + } + +} diff --git a/Personal/SimpleOOPExample/src/Main.java b/Personal/SimpleOOPExample/src/Main.java new file mode 100644 index 0000000..8aa3052 --- /dev/null +++ b/Personal/SimpleOOPExample/src/Main.java @@ -0,0 +1,12 @@ +public class Main { + public static void main(String[] args) throws Exception { + Coords p1 = new Coords(4, 16); + Coords p2 = new Coords(2, 8); + + Line myLine = new Line(p1, p2); + + myLine.calculateGradient(); + myLine.calculateIntercept(); + myLine.displayEquation(); + } +}