Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Kolekcija <T extends Traka>{
- protected T[] tr;
- private int maxTr;
- private int trenTr;
- private ArrayList<T> lista;
- public Kolekcija() {
- lista = new ArrayList<T>();
- }
- /*public <T>Kolekcija()
- {
- maxTr = 0;
- trenTr = 0;
- }
- public <T>Kolekcija(int n)
- {
- maxTr = n;
- trenTr= 0;
- }
- */
- public void dodaj (T traka)
- {
- if(trenTr<maxTr)
- lista.add(traka);
- else
- {
- System.out.println("Ne moze dodati vise traka!");
- }
- }
- public void obrisi(int i) {
- lista.remove(i);
- }
- public <T> void pocniSRadom(int i, int kol)
- {
- T t= lista.get(i);
- try {
- tr[i].kreceRad(kol);
- }
- catch(MaximumCapacityExceeded e) {
- System.out.println(e);
- }
- }
- public <T> void staniSRadom()
- {
- for(int i=0; i<trenTr; i++)
- tr[i].stajeRad();
- }
- public <T> void staniSRadom(int i) {
- tr[i-1].stajeRad();
- }
- public void writeInFile(String ime) {
- T t;
- try (BufferedWriter b=new BufferedWriter (new FileWriter(ime));)
- {
- for (int i=0; i<lista.size();i++)
- {
- t=lista.get(i);
- t.UpisTrake(b);
- }
- }
- catch (IOException e)
- {
- System.out.println(e);
- }
- }
- void Print() {
- System.out.println(lista);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement