Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package figury.zad6;
- /**
- *
- * @author bomba
- */
- public class Linia {
- private Punkt A;
- private Punkt B;
- Linia(){
- A = new Punkt();
- B = new Punkt();
- }
- Linia(Punkt A, Punkt B){ // konstruktor parametrowy
- if(!A.equals(B)){
- this.A = new Punkt(A);
- this.B = new Punkt(B);
- }
- else{
- System.out.println("Te punkty nie tworzą linii");
- }
- }
- Linia(Linia AB){ // konstruktor kopiujący
- this.A = AB.getA();
- this.B = AB.getB();
- }
- public void przesun(int dx, int dy){
- this.A.przesun(dx, dy);
- this.B.przesun(dx, dy);
- }
- @Override
- public String toString(){
- return "Linia{" + A.toString() + " " + B.toString() + '}';
- }
- // metoda sprawdza czy linie mają wspólny Punkt
- public boolean SprawdzeniePunktow(Linia A, Linia B){
- if(A.getA().getX() == B.getA().getX() && A.getA().getY() == B.getA().getY()) return true;
- if(A.getA().getX() == B.getB().getX() && A.getA().getY() == B.getB().getY()) return true;
- if(A.getB().getX() == B.getA().getX() && A.getB().getY() == B.getA().getY()) return true;
- if(A.getB().getX() == B.getB().getX() && A.getB().getY() == B.getB().getY()) return true;
- return false;
- }
- public void setA(Punkt A){ this.A = A; }
- public void setB(Punkt B){ this.B = B; }
- public Punkt getA(){ return A; }
- public Punkt getB(){ return B; }
- @Override
- public boolean equals(Object obj) {
- if(obj == null) return false;
- if(obj == this) return true;
- if(!(obj instanceof Punkt)) return false;
- Linia l = (Linia) obj;
- boolean result = true;
- if(l.getA().equals(A)){
- if(l.getA().equals(B))
- return false;
- }
- if(l.getB().equals(A)){
- if(l.getB().equals(B))
- result = false;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement