Advertisement
Voldemord

[Java] Po co ja żyje

Apr 25th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package Ludzie;
  6.  
  7. /**
  8.  *
  9.  * @author student
  10.  */
  11. public class Main {
  12.  
  13.     /**
  14.      * @param args the command line arguments
  15.      */
  16.     public static void main(String[] args) throws Exception {
  17.  
  18.        
  19.         Osoby a = new Osoby();
  20.     }
  21. }
  22.  
  23.  
  24. /*
  25.  * To change this template, choose Tools | Templates
  26.  * and open the template in the editor.
  27.  */
  28. package Ludzie;
  29. import java.util.Scanner;
  30. /**
  31.  *
  32.  * @author student
  33.  */
  34. public class Osoby {
  35.     private Osoba[] Tablica = new Osoba[10];
  36.    
  37.     public Osoby() {
  38.         for(int i = 0;  i < 10; ++i){
  39.             try{
  40.                 System.out.println("podej osoby[" + i + "]: ");
  41.                 Scanner scanner = new Scanner(System.in);
  42.                 System.out.print("imie: ");
  43.                 String a = scanner.nextLine();
  44.                 System.out.print("nazwisko: ");
  45.                 String b = scanner.nextLine();
  46.                 this.Tablica[i] = new Osoba(a,b);
  47.             }catch(Exception e){
  48.                 this.Tablica[i] = null;
  49.             }
  50.         }
  51. }
  52. }
  53.  
  54.  
  55. /*
  56.  * To change this template, choose Tools | Templates
  57.  * and open the template in the editor.
  58.  */
  59. package Ludzie;
  60.  
  61. /**
  62.  *
  63.  * @author student
  64.  */
  65. public class BrakDanych extends Exception {
  66.  
  67.     /**
  68.      * Creates a new instance of
  69.      * <code>BrakDanych</code> without detail message.
  70.      */
  71.     public BrakDanych() {
  72.     }
  73.  
  74.     /**
  75.      * Constructs an instance of
  76.      * <code>BrakDanych</code> with the specified detail message.
  77.      *
  78.      * @param msg the detail message.
  79.      */
  80.     public BrakDanych(String msg) {
  81.         super(msg);
  82.     }
  83. }
  84.  
  85.  
  86.  
  87. package Ludzie;
  88.  
  89.  
  90. public class Osoba {
  91.     private String Imie;
  92.     private String Nazwisko;
  93.    
  94.     public Osoba(String im, String na) throws BrakDanych{
  95.         if(im.isEmpty() || na.isEmpty())
  96.             throw new BrakDanych( "Brak" + ((im.isEmpty())? " Imienia" : "") + ((na.isEmpty())? "Nazwiska" : "") );
  97.         this.Imie = im;
  98.         this.Nazwisko = na;
  99.     }
  100.    
  101.    public String getImie(){
  102.        return this.Imie;
  103.    }
  104.    
  105.    public String getNazwisko(){
  106.        return this.Nazwisko;
  107.    }
  108.    
  109.    public void setImie(String im){
  110.        this.Imie = im;
  111.    }
  112.    public void setNazwisko(String na){
  113.        this.Nazwisko = na;
  114.    }
  115.    
  116.    @Override
  117.    public String toString(){
  118.        return this.Imie + " " + this.Nazwisko;
  119.    }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement