Advertisement
Talar97

Zadanie klasy

Jan 31st, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1. MAIN.java
  2. package com.Talar;
  3.  
  4. import java.io.*;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         Operator play = new Operator("Play", 15);
  10.         Telefon nadawca = new Telefon("Samsung", "Note","600444777",2506,3560);
  11.         Telefon odbiorca = new Telefon("HTC", "Desire 820","500333666",1235,600);
  12.  
  13.         //nadawca.wyswietlInformacje();
  14.         //odbiorca.wyswietlInformacje();
  15.         //nadawca.wyslijSms(odbiorca, "Chuj ci na pysk pedale");
  16.  
  17.         play.dodajTelefon(nadawca);
  18.         play.dodajTelefon(odbiorca);
  19.         play.wyswietlWszystkieTelefony();
  20.  
  21.         play.zmienWszystkieCeny(1.25);
  22.         play.wyswietlWszystkieTelefony();
  23.     }
  24. }
  25.  
  26. Telefon.java
  27. package com.Talar;
  28.  
  29. import java.io.Serializable;
  30.  
  31. public class Telefon implements Serializable{
  32.     private String producent;
  33.     private String model;
  34.     private String numer;
  35.     private int id;
  36.  
  37.     private double cena;
  38.  
  39.  
  40.     public Telefon(String prod, String mod, String num, int id, double cena){
  41.         this.producent = prod;
  42.         this.model = mod;
  43.         this.numer = num;
  44.         this.id = id;
  45.         this.cena = cena;
  46.     }
  47.  
  48.     public void wyslijSms(Telefon odbiorca, String wiadomosc){
  49.         System.out.println("Wiadomość z numeru: " + this.getNumer() + " na numer " + odbiorca.getNumer() + ":");
  50.         System.out.println(wiadomosc);
  51.     }
  52.  
  53.     public void wyswietlInformacje(){
  54.         System.out.println("Producent: " + this.producent + "" +
  55.                 ", Model: " + this.model + "" +
  56.                 ", Numer: " + this.numer + "" +
  57.                 ", Id: " + this.numer + "" +
  58.                 ", Cena: " + this.cena + "");
  59.     }
  60.  
  61.     public String getProducent() {
  62.         return producent;
  63.     }
  64.  
  65.     public String getModel() {
  66.         return model;
  67.     }
  68.  
  69.     public String getNumer() {
  70.         return numer;
  71.     }
  72.  
  73.     public int getId() {
  74.         return id;
  75.     }
  76.  
  77.     public double getCena() {
  78.         return cena;
  79.     }
  80.  
  81.     public void setCena(double cena) {
  82.         this.cena = cena;
  83.     }
  84. }
  85.  
  86. Operator.java
  87. package com.Talar;
  88.  
  89. public class Operator {
  90.     private String nazwa;
  91.     private Telefon [] zbior;
  92.  
  93.     public Operator(){
  94.         this.nazwa = "Orange";
  95.         this.zbior = new Telefon[25];
  96.  
  97.         for(int i = 0; i<zbior.length; i++){
  98.             zbior[i] = null;
  99.         }
  100.     }
  101.  
  102.     public Operator(String nazwa, int rozmiar){
  103.         this.nazwa = nazwa;
  104.         if(rozmiar>0) this.zbior = new Telefon[rozmiar];
  105.  
  106.         for(int i = 0; i<rozmiar; i++){
  107.             zbior[i] = null;
  108.         }
  109.     }
  110.  
  111.     public void dodajTelefon(Telefon tel){
  112.         for(int i=0; i<zbior.length; i++){
  113.             if(zbior[i]==null){
  114.                 zbior[i] = tel;
  115.                 break;
  116.             }
  117.         }
  118.     }
  119.  
  120.     public void wyswietlWszystkieTelefony(){
  121.         for(int i = 0; i< zbior.length; i++){
  122.             if(zbior[i]!=null) zbior[i].wyswietlInformacje();
  123.         }
  124.     }
  125.  
  126.     public void zmienWszystkieCeny(double modyfikator){
  127.         for(int i = 0; i<zbior.length; i++){
  128.             if(zbior[i]!=null) zbior[i].setCena(zbior[i].getCena()*modyfikator);
  129.         }
  130.     }
  131.  
  132.     public String getNazwa() {
  133.         return nazwa;
  134.     }
  135.  
  136.     public Telefon[] getZbior() {
  137.         return zbior;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement