Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Ludzie;
- /**
- *
- * @author student
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws Exception {
- Osoby a = new Osoby();
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Ludzie;
- import java.util.Scanner;
- /**
- *
- * @author student
- */
- public class Osoby {
- private Osoba[] Tablica = new Osoba[10];
- public Osoby() {
- for(int i = 0; i < 10; ++i){
- try{
- System.out.println("podej osoby[" + i + "]: ");
- Scanner scanner = new Scanner(System.in);
- System.out.print("imie: ");
- String a = scanner.nextLine();
- System.out.print("nazwisko: ");
- String b = scanner.nextLine();
- this.Tablica[i] = new Osoba(a,b);
- }catch(Exception e){
- this.Tablica[i] = null;
- }
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Ludzie;
- /**
- *
- * @author student
- */
- public class BrakDanych extends Exception {
- /**
- * Creates a new instance of
- * <code>BrakDanych</code> without detail message.
- */
- public BrakDanych() {
- }
- /**
- * Constructs an instance of
- * <code>BrakDanych</code> with the specified detail message.
- *
- * @param msg the detail message.
- */
- public BrakDanych(String msg) {
- super(msg);
- }
- }
- package Ludzie;
- public class Osoba {
- private String Imie;
- private String Nazwisko;
- public Osoba(String im, String na) throws BrakDanych{
- if(im.isEmpty() || na.isEmpty())
- throw new BrakDanych( "Brak" + ((im.isEmpty())? " Imienia" : "") + ((na.isEmpty())? "Nazwiska" : "") );
- this.Imie = im;
- this.Nazwisko = na;
- }
- public String getImie(){
- return this.Imie;
- }
- public String getNazwisko(){
- return this.Nazwisko;
- }
- public void setImie(String im){
- this.Imie = im;
- }
- public void setNazwisko(String na){
- this.Nazwisko = na;
- }
- @Override
- public String toString(){
- return this.Imie + " " + this.Nazwisko;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement