Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. /**
  2. * Created by Wojtek on 2017-04-02.
  3. */
  4. public class Main {
  5. public static void main(String[] args) throws CloneNotSupportedException{
  6. Punkt punkt = new Punkt(0, 0);
  7.  
  8. Odcinek odcinek = new Odcinek(punkt, punkt);
  9. Odcinek odcinek1 = (Odcinek) odcinek.clone();
  10.  
  11. System.out.println(odcinek.getStart().getX());
  12. System.out.println(odcinek1.getStart().getX());
  13. System.out.println("Porównanie "+(odcinek==odcinek1));
  14.  
  15. System.out.println(odcinek.getStart().getX());
  16. System.out.println(odcinek.getStart().getY());
  17. System.out.println("Porównanie "+(odcinek.equals(odcinek1)));
  18. }
  19. }
  20.  
  21. /**
  22. * Created by Wojtek on 2017-04-02.
  23. */
  24. public class Punkt implements Cloneable{
  25. private int x = 0;
  26. private int y = 0;
  27.  
  28. public Punkt(int x, int y){
  29. this.x = x;
  30. this.y = y;
  31. }
  32.  
  33. public int getX() {
  34. return x;
  35. }
  36.  
  37. public int getY() {
  38. return y;
  39. }
  40.  
  41. public void setX(int x) {
  42. this.x = x;
  43. }
  44.  
  45. public void setY(int y) {
  46. this.y = y;
  47. }
  48.  
  49. @Override
  50. public Object clone() throws CloneNotSupportedException {
  51. return super.clone();
  52. }
  53. }
  54.  
  55. /**
  56. * Created by Wojtek on 2017-04-02.
  57. */
  58. public class Odcinek implements Cloneable{
  59. private Punkt start = null;
  60. private Punkt koniec = null;
  61.  
  62. private Odcinek(){
  63.  
  64. }
  65.  
  66. public Odcinek(Punkt start, Punkt koniec){
  67. this.start = start;
  68. this.koniec = koniec;
  69. }
  70.  
  71. public Punkt getStart() {
  72. return start;
  73. }
  74.  
  75. public Punkt getKoniec() {
  76. return koniec;
  77. }
  78.  
  79. public void setStart(Punkt start) {
  80. this.start = start;
  81. }
  82.  
  83. public void setKoniec(Punkt koniec) {
  84. this.koniec = koniec;
  85. }
  86.  
  87. @Override
  88. public Object clone() throws CloneNotSupportedException {
  89. Odcinek odcinek = new Odcinek();
  90. odcinek.setStart((Punkt) getStart().clone());
  91. odcinek.setKoniec((Punkt) getKoniec().clone());
  92.  
  93. return odcinek;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement