Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class Osoba{
- String imie;
- String nazwisko;
- int rokUrodzenia;
- boolean plec;
- short kodPocztowy;
- public Osoba() throws NiewlasciweDaneException{
- try{
- Scanner in = new Scanner(System.in);
- System.out.println("Podaj imie:");
- this.imie = in.nextLine();
- System.out.println("Podaj nazwisko:");
- this.nazwisko = in.nextLine();
- System.out.println("Podaj rok urodzenia:");
- this.rokUrodzenia = in.nextInt();
- System.out.println("Podaj plec (M - true/K - false):");
- this.plec = in.nextBoolean();
- System.out.println("Podaj kod pocztowy:");
- this.kodPocztowy = in.nextShort();
- } catch(InputMismatchException e){
- throw new NiewlasciweDaneException("Podano niewlasciwe dane: " + e.getMessage());
- }
- }
- public static void main(String[] args) throws NiewlasciweDaneException{
- Osoba os1 = new Osoba();
- Osoba os2 = new Osoba();
- Osoba os3 = new Osoba();
- }
- }
- class NiewlasciweDaneException extends Exception{
- public NiewlasciweDaneException(String msg){
- super(msg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement