Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point{
- double x, y; // cooordinates
- void getPoint() { // read coordinates
- System.out.print("Enter coordinates: ");
- x = Console.readDouble();
- y = Console.readDouble();
- }
- void putPoint() { // write point
- System.out.print("(" + x + "," + y + ")");
- }
- double distance(Point p) { // distance from the origin
- return(Math.sqrt(x*x+y*y));
- }
- Point midPoint(Point p){
- Point mid = new Point();
- mid.x = (x + p.x)/2.0;
- mid.y = (y + p.y)/2.0;
- return mid;
- }
- public static void main(String [] args){
- Point p1 = new Point();
- p1.getPoint();
- Point p2 = new Point();
- p2.getPoint();
- Point p3;
- p3 = p1.midPoint(p2);
- p3.putPoint();
- //System.out.println("The distance between them is : " + p1.distance(p2) );
- //System.out.println(" The midpoint of the two points entered is:"+ p1.midPoint(p2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment