Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN.java
- package com.Talar;
- import java.io.*;
- public class Main {
- public static void main(String[] args) {
- Operator play = new Operator("Play", 15);
- Telefon nadawca = new Telefon("Samsung", "Note","600444777",2506,3560);
- Telefon odbiorca = new Telefon("HTC", "Desire 820","500333666",1235,600);
- //nadawca.wyswietlInformacje();
- //odbiorca.wyswietlInformacje();
- //nadawca.wyslijSms(odbiorca, "Chuj ci na pysk pedale");
- play.dodajTelefon(nadawca);
- play.dodajTelefon(odbiorca);
- play.wyswietlWszystkieTelefony();
- play.zmienWszystkieCeny(1.25);
- play.wyswietlWszystkieTelefony();
- }
- }
- Telefon.java
- package com.Talar;
- import java.io.Serializable;
- public class Telefon implements Serializable{
- private String producent;
- private String model;
- private String numer;
- private int id;
- private double cena;
- public Telefon(String prod, String mod, String num, int id, double cena){
- this.producent = prod;
- this.model = mod;
- this.numer = num;
- this.id = id;
- this.cena = cena;
- }
- public void wyslijSms(Telefon odbiorca, String wiadomosc){
- System.out.println("Wiadomość z numeru: " + this.getNumer() + " na numer " + odbiorca.getNumer() + ":");
- System.out.println(wiadomosc);
- }
- public void wyswietlInformacje(){
- System.out.println("Producent: " + this.producent + "" +
- ", Model: " + this.model + "" +
- ", Numer: " + this.numer + "" +
- ", Id: " + this.numer + "" +
- ", Cena: " + this.cena + "");
- }
- public String getProducent() {
- return producent;
- }
- public String getModel() {
- return model;
- }
- public String getNumer() {
- return numer;
- }
- public int getId() {
- return id;
- }
- public double getCena() {
- return cena;
- }
- public void setCena(double cena) {
- this.cena = cena;
- }
- }
- Operator.java
- package com.Talar;
- public class Operator {
- private String nazwa;
- private Telefon [] zbior;
- public Operator(){
- this.nazwa = "Orange";
- this.zbior = new Telefon[25];
- for(int i = 0; i<zbior.length; i++){
- zbior[i] = null;
- }
- }
- public Operator(String nazwa, int rozmiar){
- this.nazwa = nazwa;
- if(rozmiar>0) this.zbior = new Telefon[rozmiar];
- for(int i = 0; i<rozmiar; i++){
- zbior[i] = null;
- }
- }
- public void dodajTelefon(Telefon tel){
- for(int i=0; i<zbior.length; i++){
- if(zbior[i]==null){
- zbior[i] = tel;
- break;
- }
- }
- }
- public void wyswietlWszystkieTelefony(){
- for(int i = 0; i< zbior.length; i++){
- if(zbior[i]!=null) zbior[i].wyswietlInformacje();
- }
- }
- public void zmienWszystkieCeny(double modyfikator){
- for(int i = 0; i<zbior.length; i++){
- if(zbior[i]!=null) zbior[i].setCena(zbior[i].getCena()*modyfikator);
- }
- }
- public String getNazwa() {
- return nazwa;
- }
- public Telefon[] getZbior() {
- return zbior;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement