radko93

Grupa

Feb 28th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package L1;
  2.  
  3. public class Grupa implements Predicate {
  4.     Student tab[];
  5.     double srmin;
  6.  
  7.     public Grupa(int liczba) {
  8.         tab = new Student[liczba];
  9.  
  10.     }
  11.  
  12.     public Grupa(double srednia1) {
  13.         srmin = srednia1;
  14.     }
  15.  
  16.     public void dodaj(Student s) { // metoda do dodawania studentow
  17.         for (int i = 0; i < tab.length; i++) {
  18.             while (tab[i] == null) {
  19.                 tab[i] = s;
  20.             }
  21.         }
  22.  
  23.     }
  24.  
  25.     @Override
  26.     public boolean evaluate(Object ob) {
  27.  
  28.         return ((Student) ob).srednia > srmin;
  29.     }
  30.  
  31.     public void Filtruj() {
  32.         Iterator it = new Iterek(tab);
  33.         it.first();
  34.         Iterator fit = new Filter(it, new Grupa(3.20));
  35.         fit.first();
  36.  
  37.         while (!fit.isDone()) {
  38.             Student st = (Student) fit.current();
  39.             System.out.println(st);
  40.  
  41.             fit.next();
  42.         }
  43.     }
  44.  
  45.     public static void main(String[] args) {
  46.         Grupa uczelnia = new Grupa(5); // tworze obiekt i dodaje studentow
  47.         uczelnia.dodaj(new Student("Czajkowski", 4.50));
  48.         uczelnia.dodaj(new Student("Marecki", 3.0));
  49.         uczelnia.dodaj(new Student("Stefaniak", 4.20));
  50.         uczelnia.dodaj(new Student("Zdziwsław", 4.0));
  51.         uczelnia.dodaj(new Student("Borek", 3.7));
  52.         uczelnia.Filtruj();
  53.  
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment