Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //object of the class Point
- public class PointMain3
- {
- public static void main(String[] args)
- {
- Point p1 =new Point(2,3);
- Point p2 =new Point();
- System.out.println("p1: (" + p1.GetX() + ", " + p1.GetY() + ")");
- System.out.println("p2: (" + p2.GetX() + ", " + p2.GetY() + ")");
- p2.SetX(3);
- p2.SetY(5);
- System.out.println("I changed my p2.");
- System.out.println("p2: (" + p2.GetX() + ", " + p2.GetY() + ")");
- p2.translateX(-4);
- p2.translateY(3);
- System.out.println("I translated p2.");
- System.out.println("p2: (" + p2.GetX() + ", " + p2.GetY() + ")");
- System.out.println("The distance between p1 and p2 is " + p2.calcdistance(2, -1, 3, 8));
- System.out.println("The slope of the line that p1 and p2 create is " + p2.calcSlope(2,-1,3,8));
- }
- }
- //the main class
- public class Point
- {
- private int x;
- private int y;
- public Point()
- {
- x=1;
- y=1;
- }
- public Point(int x1, int y1)
- {
- x=x1;
- y=y1;
- }
- public int GetX()
- {
- return x;
- }
- public int GetY()
- {
- return y;
- }
- public void SetX(int x1)
- {
- x=x1;
- }
- public void SetY(int y1)
- {
- y=y1;
- }
- public void translateX(int t1)
- {
- x = x+t1;
- }
- public void translateY(int t2)
- {
- y = y+t2;
- }
- public static double calcdistance(int x, int x1, int y, int y1)
- {
- return Math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
- }
- public static double calcSlope(double x, double x1, double y, double y1)
- {
- return (y1-y)/(x1-x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment