dariahinz

punkt

Mar 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package punkt;
  2.  
  3. public class Punkt {
  4.  
  5. private final double x,y;
  6. public Punkt(double x, double y) {
  7. this.x=x;
  8. this.y=y;
  9. }
  10. public double getX() {
  11. return x;
  12. }
  13. public double getY() {
  14. return y;
  15. }
  16. @Override
  17. public boolean equals(Object obj) {
  18. if(obj instanceof Punkt)
  19. {
  20. Punkt other = (Punkt)obj;
  21. return (x == other.x && y == other.y);
  22. }
  23. return false;
  24. }
  25.  
  26. @Override
  27. public int hashCode() {
  28. return super.hashCode();
  29. }
  30. @Override
  31. public String toString() {
  32. return "Instancja klasy Punkt zawierająca wpolrzedne( "+x+","+y+")";
  33. }
  34. /**
  35. * Początek układu współrzędnych.
  36. * W tym miejscu słowo kluczowe final oznacza, że statyczne
  37. * pole klasy Punkt nie może zostać zmienione.
  38. * Dotyczy to jednak samej referencji, a nie obiektu, na który
  39. * wskazuje.
  40. */
  41. public static final Punkt O = new Punkt(0, 0);
  42. /**
  43. * Punkt (1,0) w układzie współrzędnych
  44. */
  45. public static final Punkt E_X = new Punkt(1, 0);
  46.  
  47. /**
  48. * Punkt (0,1) w układzie współrzędnych
  49. */
  50. public static final Punkt E_Y = new Punkt(0, 1);
  51.  
  52.  
  53. }
Add Comment
Please, Sign In to add comment