daniel_lawson9999

Daniel Lawson Chapter 8 Exercises 2-6

Sep 22nd, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. Daniel Lawson
  2. 9/22/2016
  3.  
  4. Exercise 2:
  5. public void flip(){
  6.     int tempX = x;
  7.     x = -y;
  8.     y = -tempX;
  9. }
  10. Exercise 3:
  11. public int manhattanDistance(Point other){
  12.  return (Math.abs(x-other.getX()) + Math.abs(y-other.getY()));
  13. }
  14. Exercise 4:
  15. public boolean isVertical(Point other){
  16.  return(x == other.getX());
  17. }
  18. Exercise 5:
  19. public double slope(Point other){
  20.  if(x == other.getX())throw new IllegalArgumentException("Your x values can't be the same!");
  21.  return Math.round((((y2-y1)/(x2-x1)) * 10000.0) / 10000.0); //return((y-other.getY())/(x-other.getX));
  22. }
  23. Exercise 6:
  24. public boolean isCollinear(Point p1, Point p2){
  25.  return(slope(p1) == slope(p1));
  26.  }
Advertisement
Add Comment
Please, Sign In to add comment