Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ZITR1;
- // Задатак RZITR1: Додати програм на месту три тачке како би се добила порука:
- // Items:
- // 4
- // 2
- // 1
- // 5
- // 3
- class Client {
- Aggregate ag;
- Iterator it;
- Client(){
- ag=new ConcreteAggregate();
- it = new ConcreteIterator((ConcreteAggregate) ag);
- }
- public static void main(String args[]) {
- Client cl = new Client();
- cl.printItems();
- }
- void printItems() {
- System.out.println("Items:");
- it.First();
- while (it.IsEnd()) {
- System.out.println(it.currentItem());
- it.Next();
- }
- }}
- abstract class Aggregate{
- int n[];
- abstract Iterator createIterator();
- int getItem(int indeks) {return n[indeks];}
- int getItemsNumber(){return n.length;}
- }
- class ConcreteAggregate extends Aggregate {
- ConcreteAggregate() { n = new int[5]; n[0]=4; n[1]=2; n[2]=1; n[3]=5; n[4]=3;}
- Iterator createIterator() { return new ConcreteIterator(this);}
- }
- abstract class Iterator{
- abstract void First();
- abstract void Next();
- abstract boolean IsEnd();
- abstract int currentItem();
- }
- class ConcreteIterator extends Iterator {
- ConcreteAggregate ag;
- int indeks;
- ConcreteIterator(ConcreteAggregate ag1) {ag = ag1;}
- void First() {indeks = 0;}
- void Next() {indeks++;}
- boolean IsEnd () {return indeks < ag.getItemsNumber();}
- int currentItem() {return ag.getItem(indeks);}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement