Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. Telefon[] tt = {new Smartfon(), new Komorka(), new Telefon()};
  5. for(int i = 0; i < 10; i++) {
  6. if(i%2==0) {
  7. tt[2].zadzwon("123-456-789");
  8. }else {
  9. tt[2].zadzwon("234-567-890");
  10. }
  11. }
  12. for(int i = 0; i < 10; i++) {
  13. if(i%2==0) {
  14. tt[1].zadzwon("123-456-789");
  15. }else {
  16. tt[1].zadzwon("234-567-890");
  17. }
  18. }
  19. for(int i = 0; i < 10; i++) {
  20. if(i == 5 || i == 9) {
  21. tt[0].zadzwon("466-344-233");
  22. continue;
  23. }
  24. if(i%2==0) {
  25. tt[0].zadzwon("123-456-789");
  26. }else {
  27. tt[0].zadzwon("345-567-789");
  28. }
  29. }
  30. System.out.println("Telefon");
  31. tt[2].wyswietlHistoriePolaczen();
  32. System.out.println("Komórka");
  33. tt[1].wyswietlHistoriePolaczen();
  34. System.out.println("Smartfon");
  35. tt[0].wyswietlHistoriePolaczen();
  36.  
  37. }
  38.  
  39. }
  40.  
  41. public class Komorka extends Telefon{
  42. String[] spisPolaczen;
  43. public Komorka() {
  44. spisPolaczen = new String[10];
  45. }
  46. public void wyswietlHistoriePolaczen() {
  47. for(int i = 0; i < spisPolaczen.length; i++) {
  48. System.out.println(spisPolaczen[i]);
  49. }
  50. }
  51. private int i = 0;
  52. @Override public void zadzwon(String numer) {
  53. System.out.println("Dzwonisz pod numer: "+numer);
  54. spisPolaczen[i++] = numer;
  55. if(i==10) {
  56. i=0;
  57. }
  58. }
  59. }
  60.  
  61.  
  62. public class Osoba {
  63. private String imie;
  64. private String nazwisko;
  65. private String numer;
  66. public Osoba() {
  67.  
  68. }
  69. public String getImie() {
  70. return imie;
  71. }
  72. public void setImie(String imie) {
  73. this.imie = imie;
  74. }
  75. public String getNazwisko() {
  76. return nazwisko;
  77. }
  78. public void setNazwisko(String nazwisko) {
  79. this.nazwisko = nazwisko;
  80. }
  81. public String getNumer() {
  82. return numer;
  83. }public void setNumer(String numer) {
  84. this.numer = numer;
  85. }
  86. }
  87.  
  88.  
  89. public class Smartfon extends Komorka {
  90. Osoba[] znajomi;
  91. public Smartfon() {
  92. znajomi = new Osoba[2];
  93. znajomi[0] = new Osoba();
  94. znajomi[1] = new Osoba();
  95. znajomi[0].setImie("Jan");
  96. znajomi[0].setNazwisko("Dzban");
  97. znajomi[0].setNumer("345-567-789");
  98. znajomi[1].setImie("Jan");
  99. znajomi[1].setNazwisko("Kowalski");
  100. znajomi[1].setNumer("466-344-233");
  101. }
  102. private boolean znajomy = false;
  103. @Override public void wyswietlHistoriePolaczen() {
  104. for(int i = 0; i < spisPolaczen.length; i++) {
  105. znajomy = false;
  106. for(int j = 0; j < znajomi.length; j++) {
  107. //System.out.println("spis "+spisPolaczen[i]);
  108. //System.out.println("znajomi "+znajomi[j].getNumer());
  109. if(spisPolaczen[i] == znajomi[j].getNumer()) {
  110. System.out.println(znajomi[j].getImie()+ " "+znajomi[j].getNazwisko() + " " + znajomi[j].getNumer());
  111. znajomy = true;
  112. break;
  113. }
  114. }
  115. if(znajomy)
  116. continue;
  117. System.out.println(spisPolaczen[i]);
  118. }
  119. }
  120. private int i = 0;
  121. @Override public void zadzwon(String numer) {
  122. System.out.println("Dzwonisz pod numer: "+numer);
  123. spisPolaczen[i++] = numer;
  124. if(i==10) {
  125. i=0;
  126. }
  127. }
  128. }
  129.  
  130.  
  131. import java.awt.*;
  132. public class Telefon {
  133. String interfejsKomunikacyjny;
  134. Color color;
  135. public void zadzwon(String numer) {
  136. System.out.println("Dzwonisz pod numer: "+numer);
  137. }
  138. public void wyswietlHistoriePolaczen() {
  139. System.out.println("brak historii");
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement