Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Telefon[] tt = {new Smartfon(), new Komorka(), new Telefon()};
- for(int i = 0; i < 10; i++) {
- if(i%2==0) {
- tt[2].zadzwon("123-456-789");
- }else {
- tt[2].zadzwon("234-567-890");
- }
- }
- for(int i = 0; i < 10; i++) {
- if(i%2==0) {
- tt[1].zadzwon("123-456-789");
- }else {
- tt[1].zadzwon("234-567-890");
- }
- }
- for(int i = 0; i < 10; i++) {
- if(i == 5 || i == 9) {
- tt[0].zadzwon("466-344-233");
- continue;
- }
- if(i%2==0) {
- tt[0].zadzwon("123-456-789");
- }else {
- tt[0].zadzwon("345-567-789");
- }
- }
- System.out.println("Telefon");
- tt[2].wyswietlHistoriePolaczen();
- System.out.println("Komórka");
- tt[1].wyswietlHistoriePolaczen();
- System.out.println("Smartfon");
- tt[0].wyswietlHistoriePolaczen();
- }
- }
- public class Komorka extends Telefon{
- String[] spisPolaczen;
- public Komorka() {
- spisPolaczen = new String[10];
- }
- public void wyswietlHistoriePolaczen() {
- for(int i = 0; i < spisPolaczen.length; i++) {
- System.out.println(spisPolaczen[i]);
- }
- }
- private int i = 0;
- @Override public void zadzwon(String numer) {
- System.out.println("Dzwonisz pod numer: "+numer);
- spisPolaczen[i++] = numer;
- if(i==10) {
- i=0;
- }
- }
- }
- public class Osoba {
- private String imie;
- private String nazwisko;
- private String numer;
- public Osoba() {
- }
- public String getImie() {
- return imie;
- }
- public void setImie(String imie) {
- this.imie = imie;
- }
- public String getNazwisko() {
- return nazwisko;
- }
- public void setNazwisko(String nazwisko) {
- this.nazwisko = nazwisko;
- }
- public String getNumer() {
- return numer;
- }public void setNumer(String numer) {
- this.numer = numer;
- }
- }
- public class Smartfon extends Komorka {
- Osoba[] znajomi;
- public Smartfon() {
- znajomi = new Osoba[2];
- znajomi[0] = new Osoba();
- znajomi[1] = new Osoba();
- znajomi[0].setImie("Jan");
- znajomi[0].setNazwisko("Dzban");
- znajomi[0].setNumer("345-567-789");
- znajomi[1].setImie("Jan");
- znajomi[1].setNazwisko("Kowalski");
- znajomi[1].setNumer("466-344-233");
- }
- private boolean znajomy = false;
- @Override public void wyswietlHistoriePolaczen() {
- for(int i = 0; i < spisPolaczen.length; i++) {
- znajomy = false;
- for(int j = 0; j < znajomi.length; j++) {
- //System.out.println("spis "+spisPolaczen[i]);
- //System.out.println("znajomi "+znajomi[j].getNumer());
- if(spisPolaczen[i] == znajomi[j].getNumer()) {
- System.out.println(znajomi[j].getImie()+ " "+znajomi[j].getNazwisko() + " " + znajomi[j].getNumer());
- znajomy = true;
- break;
- }
- }
- if(znajomy)
- continue;
- System.out.println(spisPolaczen[i]);
- }
- }
- private int i = 0;
- @Override public void zadzwon(String numer) {
- System.out.println("Dzwonisz pod numer: "+numer);
- spisPolaczen[i++] = numer;
- if(i==10) {
- i=0;
- }
- }
- }
- import java.awt.*;
- public class Telefon {
- String interfejsKomunikacyjny;
- Color color;
- public void zadzwon(String numer) {
- System.out.println("Dzwonisz pod numer: "+numer);
- }
- public void wyswietlHistoriePolaczen() {
- System.out.println("brak historii");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement