0% found this document useful (0 votes)
25 views1 page

EX02

The document describes an exercise to create a Point class with methods like constructors, getters/setters, toString, equals, move, distance, getPointInHalfWay, and LineEquation. It also describes writing a Tester class to test the Point methods.

Uploaded by

mo2419270
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

EX02

The document describes an exercise to create a Point class with methods like constructors, getters/setters, toString, equals, move, distance, getPointInHalfWay, and LineEquation. It also describes writing a Tester class to test the Point methods.

Uploaded by

mo2419270
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Advanced Programming (0303204)

Exercise 2 :
In this exercise, write a class named Point, the class has two instance variables _x, _y.
1. Write a default constructor public Point () that initializes the point coordinates to 0.
2. Write another constructor public Point( int x, int y) that passes values to instance variables.
3. Write a copy constructor public Point(Point other) that takes an object point as a parameter
to pass values to instance variables.
4. Write the get and set methods.
5. Write toString method public String toString( ), that returns a string that represent the point
coordinates in the format (x, y).
6. Write a method public boolean equals(Point p) that checks if this point is equal to Point p
rassed as an argument thus it returns true otherwise it return false.
7. Write a method public void move(int dx, int dy) that moves the point coordinates to new
positions according to dx and dy respectively.
8. Write a method public double distance(Point p) that calculates the distance between this
point and parameter point p.
9. Write a method public Point getPointInHalfWay() that return the point in the middle
between this point and the origin.
10. Write a method public LineEquation(int x1, int y1, int x2, int y2) that takes two points:
(x1, y1), (x2, y2) and returns the equation of Line that contains these two points.
11. Write a tester named Tester.java and test all the methods in Point class.

Submission Guidelines
1. Write the program in class named Point.java
2. Write the tester in class named Tester.java , create point object and test all the methods in
Point class.
3. Submit this exercise individually
4. The classes are bagged in a zip or rar file single, called Ex2.zip or Ex2.rar.

You might also like