Advertisement
Guest User

PointCLient

a guest
Dec 3rd, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. /*
  2. Enhance your Point class to include:
  3. toString method //produces and returns the desired string, e.g (19, 5)
  4. getQuadrant method //returns the quadrant in which (x, y) lies (or 0 if on axis)
  5. distanceToOrigin //returns distance from (x, y) to origin (use double)
  6. */
  7. import java.util.*;
  8.  
  9. public class PointClient{
  10. public static void main(String[] args){
  11.  
  12. Point mooDefault = new Point();
  13. System.out.println("mooDefault = " + mooDefault);
  14.  
  15. Scanner console = new Scanner(System.in);
  16. int x = getNumber("Enter x-value: ", console);
  17. int y = getNumber("Enter y-value: ", console);
  18.  
  19. Point moo = new Point(x,y);
  20. System.out.println("moo = " + moo);
  21.  
  22. moo.translate(2,2);
  23. moo.setXY(moo.getX(),0);
  24. moo.translate(0,19);
  25. moo.setXY(moo.getY(),moo.getX());
  26. System.out.println("(" + moo.getX() + ", " + moo.getY() + ")");
  27. System.out.println("Quadrant: " + moo.getQuadrant());
  28. System.out.println("Distance to origin: " + moo.distanceToOrigin());
  29.  
  30. System.out.println("x = " + x); //prints PointClient x (variable in PointClient scope)
  31. System.out.println("x = " + moo.getX()); //prints Point x (field in Point scope)
  32. System.out.println("moo = " + moo); //the toString method is implicitly called
  33. System.out.println("moo = " + moo.toString()); // produces same output as line above
  34. }
  35.  
  36. public static int getNumber(String prompt, Scanner console){
  37. System.out.print(prompt);
  38. int num = console.nextInt();
  39. return num;
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement