diff --git a/.gitignore b/.gitignore index ae565c3..4b1dc39 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ hs_err_pid* *.html *.css *.ctext +*.ctxt diff --git a/README.md b/README.md index 1df7f8e..646c685 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -# point +# Point +Create a Point class which has two instance variable for the x and y coordinates. +Write a constructor and one method called distance(Point otherPoint), which returns the distance between this point and otherPoint. + +Write a PointTester class which asks for two points and prints the distance between them. + +Save these classes in the src folder, and make a pull request when you are ready to submit. diff --git a/src/APLine.java b/src/APLine.java new file mode 100644 index 0000000..84a0206 --- /dev/null +++ b/src/APLine.java @@ -0,0 +1,78 @@ + +public class APLine +{ + //instance variables + double a; + double b; + double c; + + //constructors + public APLine(double a, double b, double c) + { + this.a = a; + this.b = b; + this.c = c; + } + + //methods + public double getSlope() + { + return -a/b; + } + + public boolean isOnLine(int x, int y) + { + if(this.a * x + this.b *y + this.c == 0) + { + return true; + } + else + { + return false; + } + } + + public boolean isOnLine(Point point) + { + if(this.a * point.getX() + this.b * point.getY() + this.c == 0) + { + return true; + } + else + { + return false; + } + } + + //setters and getters + public double getA() + { + return this.a; + } + + public double getB() + { + return this.b; + } + + public double getC() + { + return this.c; + } + + public void setA(int a) + { + this.a = a; + } + + public void setB(int b) + { + this.b = b; + } + + public void setC(int c) + { + this.c = c; + } + +} diff --git a/src/IncorrectlyCompletedException.java b/src/IncorrectlyCompletedException.java new file mode 100644 index 0000000..752ca25 --- /dev/null +++ b/src/IncorrectlyCompletedException.java @@ -0,0 +1,6 @@ +public class IncorrectlyCompletedException extends Exception { + public IncorrectlyCompletedException() { super(); } + public IncorrectlyCompletedException(String message) { super(message); } + public IncorrectlyCompletedException(String message, Throwable cause) { super(message, cause); } + public IncorrectlyCompletedException(Throwable cause) { super(cause); } +} diff --git a/src/MasterTester.java b/src/MasterTester.java index ba427ea..38aba17 100644 --- a/src/MasterTester.java +++ b/src/MasterTester.java @@ -1,10 +1,11 @@ import java.util.*; -public class PointTester { - public static void main (String args[]) { +public class MasterTester { + public static void main (String args[]) throws Exception { Scanner s = new Scanner (System.in); Point firstPoint = new Point (0,1); Point secondPoint = new Point (0,0); - System.out.println(firstPoint.distance(secondPoint)); + if(firstPoint.getDistance(secondPoint)!=1) + throw new IncorrectlyCompletedException(); } } diff --git a/src/Point.java b/src/Point.java new file mode 100644 index 0000000..cbc2ba0 --- /dev/null +++ b/src/Point.java @@ -0,0 +1,26 @@ + + +import java.util.*; + +public class Point { + + private double x; + private double y; + + public Point (double x, double y) { + this.x = x; + this.y = y; + } + + public double getDistance (Point otherPoint) { return(Math.sqrt(Math.pow(this.x-otherPoint.getX(), 2)+Math.pow(this.y-otherPoint.getY(), 2))); } + + public double getSlope (Point otherPoint) { return((this.x-otherPoint.getX())/(this.y-otherPoint.getY())); } + + public double getX() { return(x); } + + public double getY() { return(y); } + + public void setX() { this.x = x; } + + public void setY() { this.y = y; } +} diff --git a/src/PointTester.java b/src/PointTester.java new file mode 100644 index 0000000..4ead88b --- /dev/null +++ b/src/PointTester.java @@ -0,0 +1,20 @@ + +import java.util.*; + +public class PointTester { + public static void main (String args[]) { + Scanner s = new Scanner (System.in); + System.out.print("Please enter the x coordinate of the first point: "); + int x = s.nextInt(); + System.out.print("Please enter the y coordinate of the first point: "); + int y = s.nextInt(); + Point firstPoint = new Point (x,y); + System.out.print("Please enter the x coordinate of the second point: "); + x = s.nextInt(); + System.out.print("Please enter the y coordinate of the second point: "); + y = s.nextInt(); + Point secondPoint = new Point (x,y); + System.out.println("The distance between the two points is: "+firstPoint.getDistance(secondPoint)); + + } +} diff --git a/src/Triangle.java b/src/Triangle.java new file mode 100644 index 0000000..1ac404c --- /dev/null +++ b/src/Triangle.java @@ -0,0 +1,54 @@ + +public class Triangle +{ + //instance variables + double side1; + double side2; + double side3; + + //constructors + public Triangle(int side1, int side2, int side3) + { + this.side1 = side1; + this.side2 = side2; + this.side3 = side3; + } + + //methods + public double computePerimeter() + { + return side1+side2+side3; + } + + //getters and setters + + public double getSide1() + { + return side1; + } + + public double getSide2() + { + return side2; + } + + public double getSide3() + { + return side3; + } + + public void setSide1(int value) + { + this.side1 = value; + } + + public void setSide2(int value) + { + this.side2 = value; + } + + public void setSide3(int value) + { + this.side3 = value; + } +}