Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. public class Line {
  3.  
  4. private Point start;
  5. private Point end;
  6.  
  7. public Line(double x1, double y1, double x2, double y2) {
  8. this.start= new Point(x1, y1);
  9. this.end= new Point(x2, y2);
  10. }
  11.  
  12. public Line(Point p1, Point p2) {
  13. this.start=new Point(p1);
  14. this.end=new Point(p2);
  15. }
  16.  
  17. public Line(Line that) {
  18. this.start=new Point(that.start);
  19. this.start=new Point(that.end);
  20. }
  21.  
  22. public Point getStart() {
  23. return start;
  24. }
  25.  
  26. public Point getEnd() {
  27. return end;
  28. }
  29.  
  30. public double getStartX() {
  31. return start.getX();
  32. }
  33.  
  34. public double getStartY() {
  35. return start.getY();
  36. }
  37.  
  38. public double getEndX() {
  39. return end.getX();
  40. }
  41.  
  42. public double getEndY() {
  43. return end.getY();
  44. }
  45.  
  46. public void setStart(Point newStart) {
  47. start=newStart;
  48. }
  49.  
  50. public void setEnd(Point newEnd) {
  51. end=newEnd;
  52. }
  53.  
  54. public void setEndX(double x) {
  55. end.setX(x);
  56. }
  57.  
  58. public double length() {
  59. return Math.sqrt(Math.pow(start.getX()-end.getX(), 2)+
  60. Math.pow(start.getY()-end.getY(), 2));
  61. }
  62.  
  63. public Point midpoint() {
  64. return new Point((start.getX()+end.getX())/2,
  65. (start.getY()+end.getY())/2);
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement