Advertisement
Voldemord

[Java] Moj KOLOS XDDD

Apr 25th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1.  
  2. //Main
  3. package kolokwium;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) throws Exception {
  8.         Grupa a = new Grupa(2);
  9.         System.out.print(a);
  10.        
  11.     }
  12.    
  13. }
  14.  
  15. /*-------------------------------------*/
  16.  
  17. //Student
  18.  
  19. package kolokwium;
  20.  
  21. public class Student {
  22.  
  23.    
  24.     private String Imie;
  25.     private String Nazwisko;
  26.     private int nrAlbumu;
  27.    
  28.     public Student(String im, String na, int nr) throws BrakDanych{
  29.         if( (im == null || im.isEmpty()) ||
  30.             (im == null || im.isEmpty()) ||
  31.             (im == null || im.isEmpty()) )
  32.             throw new BrakDanych("Brak Danych");
  33.         this.Imie = im;
  34.         this.Nazwisko = na;
  35.         this.nrAlbumu = nr;
  36.     }
  37.    
  38.     public String getImie() {
  39.         return Imie;
  40.     }
  41.  
  42.     public void setImie(String Imie) {
  43.         this.Imie = Imie;
  44.     }
  45.  
  46.     public String getNazwisko() {
  47.         return Nazwisko;
  48.     }
  49.  
  50.     public void setNazwisko(String Nazwisko) {
  51.         this.Nazwisko = Nazwisko;
  52.     }
  53.  
  54.     public int getNrAlbumu() {
  55.         return nrAlbumu;
  56.     }
  57.  
  58.     public void setNrAlbumu(int nrAlbumu) {
  59.         this.nrAlbumu = nrAlbumu;
  60.     }
  61.    
  62.     @Override
  63.     public String toString(){
  64.         return "Imie: " + this.Imie + " Nazwisko: " + this.Nazwisko + " nrAlbumu: " + this.nrAlbumu;
  65.     }
  66. }
  67.  
  68. /*----------------------------*/
  69. //Grupa
  70.  
  71. package kolokwium;
  72. import java.util.Scanner;
  73.  
  74. public class Grupa {
  75.     private int n;
  76.     private Student tablica[];// = new Student[n]; //Pytanie czy po zmianie n rozmair tez sie zmieni
  77.    
  78.     public Grupa(int n) throws Exception{
  79.         this.n = n;
  80.         tablica =  new Student[n];
  81.        
  82.        
  83.         String im;
  84.         String na;
  85.         int nr;
  86.        
  87.         for(int i = 0; i < n; i++){
  88.             Scanner sc = new Scanner(System.in);
  89.             System.out.println("Osoba[" + i +"]");
  90.             System.out.print("Podaj Imie: ");
  91.             im = sc.nextLine();
  92.             System.out.print("Podaj Nazwisko: ");
  93.             na = sc.nextLine();
  94.             System.out.print("Podaj Numer: ");
  95.             nr = sc.nextInt();
  96.             tablica[i] = new Student(im,na,nr);
  97.         }
  98.     }
  99.    
  100.     @Override
  101.     public String toString(){
  102.         String ret = "";
  103.         for(int i = 0; i < this.n ; i++){
  104.             ret += tablica[i].toString() + "\n";
  105.         }
  106.         return ret;
  107.     }
  108. }
  109.  
  110. /*-----------------------*/
  111. //Brak
  112.  
  113. package kolokwium;
  114.  
  115. class BrakDanych extends Exception {
  116.  
  117.     /**
  118.      * Creates a new instance of <code>BrakDanych</code> without detail message.
  119.      */
  120.     public BrakDanych() {
  121.     }
  122.  
  123.     /**
  124.      * Constructs an instance of <code>BrakDanych</code> with the specified
  125.      * detail message.
  126.      *
  127.      * @param msg the detail message.
  128.      */
  129.     public BrakDanych(String msg) {
  130.         super(msg);
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement