Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class MyPoint here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class MyPoint
- {
- private int xPoint;
- private int yPoint;
- public MyPoint()
- {
- xPoint = 0;
- yPoint = 0;
- }
- public MyPoint(int x, int y)
- {
- xPoint = x;
- yPoint = y;
- }
- public int getXPoint()
- {
- return xPoint;
- }
- public int getYPoint()
- {
- return yPoint;
- }
- public void setXPoint(int x)
- {
- xPoint = x;
- }
- public void setYPoint(int y)
- {
- yPoint = y;
- }
- public void setXY(int x, int y)
- {
- xPoint = x;
- yPoint = y;
- }
- public double findDistance(int x, int y)
- {
- return Math.sqrt((double)Math.pow(x - this.xPoint, 2) + Math.pow(y - this.yPoint, 2));
- }
- public double findDistance(MyPoint another)
- {
- return findDistance(another.xPoint, another.yPoint);
- }
- public double findSlope(int x, int y)
- {
- return ((double)y - this.yPoint)/((double)x - this.xPoint);
- }
- public double findSlope(MyPoint another)
- {
- return findSlope(another.xPoint, another.yPoint);
- }
- public String toString()
- {
- return "(" + xPoint + "," + yPoint + ")";
- }
- }
- /**
- * Write a description of class MyPointClient here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class MyPointClient
- {
- public static void main(String[]args)
- {
- MyPoint pointA = new MyPoint();
- MyPoint pointB = new MyPoint(2,3);
- System.out.println("The current coordinate of Point A is " + pointA);
- pointA.setXPoint(7);
- pointA.setYPoint(2);
- System.out.println("The x coordinate of Point A is now " + pointA.getXPoint());
- System.out.println("The y coordinate of Point A is now " + pointA.getYPoint());
- System.out.println("The current coordinate of Point A is " + pointA);
- pointB.setXY(2,2);
- System.out.println("The coordinate of Point B is currently " + pointB);
- System.out.println("The distance from Point B to Point (5,2) is " + pointB.findDistance(5,2));
- System.out.println("The distance from Point A to Point B is " + pointA.findDistance(pointB));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment