Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3.  
  4. public class Osoba{
  5.  
  6.     String imie;
  7.     String nazwisko;
  8.     int rokUrodzenia;
  9.     boolean plec;
  10.     short kodPocztowy;
  11.  
  12.     public Osoba() throws NiewlasciweDaneException{
  13.         try{
  14.             Scanner in = new Scanner(System.in);
  15.  
  16.             System.out.println("Podaj imie:");
  17.             this.imie = in.nextLine();
  18.  
  19.             System.out.println("Podaj nazwisko:");
  20.             this.nazwisko = in.nextLine();
  21.  
  22.             System.out.println("Podaj rok urodzenia:");
  23.             this.rokUrodzenia = in.nextInt();
  24.  
  25.             System.out.println("Podaj plec (M - true/K - false):");
  26.             this.plec = in.nextBoolean();
  27.  
  28.             System.out.println("Podaj kod pocztowy:");
  29.             this.kodPocztowy = in.nextShort();
  30.  
  31.         } catch(InputMismatchException e){
  32.             throw new NiewlasciweDaneException("Podano niewlasciwe dane: " + e.getMessage());
  33.         }
  34.     }
  35.    
  36.     public static void main(String[] args) throws NiewlasciweDaneException{
  37.         Osoba os1 = new Osoba();
  38.         Osoba os2 = new Osoba();
  39.         Osoba os3 = new Osoba();
  40.     }
  41. }
  42.  
  43. class NiewlasciweDaneException extends Exception{
  44.     public NiewlasciweDaneException(String msg){
  45.         super(msg);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement