Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Main
- package kolokwium;
- public class Main {
- public static void main(String[] args) throws Exception {
- Grupa a = new Grupa(2);
- System.out.print(a);
- }
- }
- /*-------------------------------------*/
- //Student
- package kolokwium;
- public class Student {
- private String Imie;
- private String Nazwisko;
- private int nrAlbumu;
- public Student(String im, String na, int nr) throws BrakDanych{
- if( (im == null || im.isEmpty()) ||
- (im == null || im.isEmpty()) ||
- (im == null || im.isEmpty()) )
- throw new BrakDanych("Brak Danych");
- this.Imie = im;
- this.Nazwisko = na;
- this.nrAlbumu = nr;
- }
- public String getImie() {
- return Imie;
- }
- public void setImie(String Imie) {
- this.Imie = Imie;
- }
- public String getNazwisko() {
- return Nazwisko;
- }
- public void setNazwisko(String Nazwisko) {
- this.Nazwisko = Nazwisko;
- }
- public int getNrAlbumu() {
- return nrAlbumu;
- }
- public void setNrAlbumu(int nrAlbumu) {
- this.nrAlbumu = nrAlbumu;
- }
- @Override
- public String toString(){
- return "Imie: " + this.Imie + " Nazwisko: " + this.Nazwisko + " nrAlbumu: " + this.nrAlbumu;
- }
- }
- /*----------------------------*/
- //Grupa
- package kolokwium;
- import java.util.Scanner;
- public class Grupa {
- private int n;
- private Student tablica[];// = new Student[n]; //Pytanie czy po zmianie n rozmair tez sie zmieni
- public Grupa(int n) throws Exception{
- this.n = n;
- tablica = new Student[n];
- String im;
- String na;
- int nr;
- for(int i = 0; i < n; i++){
- Scanner sc = new Scanner(System.in);
- System.out.println("Osoba[" + i +"]");
- System.out.print("Podaj Imie: ");
- im = sc.nextLine();
- System.out.print("Podaj Nazwisko: ");
- na = sc.nextLine();
- System.out.print("Podaj Numer: ");
- nr = sc.nextInt();
- tablica[i] = new Student(im,na,nr);
- }
- }
- @Override
- public String toString(){
- String ret = "";
- for(int i = 0; i < this.n ; i++){
- ret += tablica[i].toString() + "\n";
- }
- return ret;
- }
- }
- /*-----------------------*/
- //Brak
- package kolokwium;
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement