Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package figury.zad6;
  7.  
  8. /**
  9. *
  10. * @author bomba
  11. */
  12. public class Linia {
  13. private Punkt A;
  14. private Punkt B;
  15.  
  16. Linia(){
  17. A = new Punkt();
  18. B = new Punkt();
  19. }
  20.  
  21. Linia(Punkt A, Punkt B){ // konstruktor parametrowy
  22. if(!A.equals(B)){
  23. this.A = new Punkt(A);
  24. this.B = new Punkt(B);
  25. }
  26. else{
  27. System.out.println("Te punkty nie tworzą linii");
  28. }
  29. }
  30.  
  31. Linia(Linia AB){ // konstruktor kopiujący
  32. this.A = AB.getA();
  33. this.B = AB.getB();
  34. }
  35.  
  36. public void przesun(int dx, int dy){
  37.  
  38. this.A.przesun(dx, dy);
  39. this.B.przesun(dx, dy);
  40. }
  41.  
  42. @Override
  43. public String toString(){
  44. return "Linia{" + A.toString() + " " + B.toString() + '}';
  45. }
  46.  
  47. // metoda sprawdza czy linie mają wspólny Punkt
  48. public boolean SprawdzeniePunktow(Linia A, Linia B){
  49. if(A.getA().getX() == B.getA().getX() && A.getA().getY() == B.getA().getY()) return true;
  50. if(A.getA().getX() == B.getB().getX() && A.getA().getY() == B.getB().getY()) return true;
  51. if(A.getB().getX() == B.getA().getX() && A.getB().getY() == B.getA().getY()) return true;
  52. if(A.getB().getX() == B.getB().getX() && A.getB().getY() == B.getB().getY()) return true;
  53.  
  54. return false;
  55. }
  56. public void setA(Punkt A){ this.A = A; }
  57. public void setB(Punkt B){ this.B = B; }
  58. public Punkt getA(){ return A; }
  59. public Punkt getB(){ return B; }
  60.  
  61.  
  62. @Override
  63. public boolean equals(Object obj) {
  64. if(obj == null) return false;
  65. if(obj == this) return true;
  66. if(!(obj instanceof Punkt)) return false;
  67. Linia l = (Linia) obj;
  68. boolean result = true;
  69. if(l.getA().equals(A)){
  70. if(l.getA().equals(B))
  71. return false;
  72. }
  73. if(l.getB().equals(A)){
  74. if(l.getB().equals(B))
  75. result = false;
  76. }
  77. return result;
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement