ADoyle4

Untitled

Mar 6th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class Point{
  2. double x, y; // cooordinates
  3.  
  4. void getPoint() { // read coordinates
  5. System.out.print("Enter coordinates: ");
  6. x = Console.readDouble();
  7. y = Console.readDouble();
  8. }
  9.  
  10. void putPoint() { // write point
  11. System.out.print("(" + x + "," + y + ")");
  12. }
  13.  
  14. double distance(Point p) { // distance from the origin
  15. return(Math.sqrt(x*x+y*y));
  16. }
  17.  
  18. Point midPoint(Point p){
  19. Point mid = new Point();
  20.  
  21. mid.x = (x + p.x)/2.0;
  22. mid.y = (y + p.y)/2.0;
  23. return mid;
  24. }
  25.  
  26. public static void main(String [] args){
  27. Point p1 = new Point();
  28. p1.getPoint();
  29. Point p2 = new Point();
  30. p2.getPoint();
  31. Point p3;
  32. p3 = p1.midPoint(p2);
  33. p3.putPoint();
  34. //System.out.println("The distance between them is : " + p1.distance(p2) );
  35. //System.out.println(" The midpoint of the two points entered is:"+ p1.midPoint(p2));
  36.  
  37.  
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment