Skip to content
Snippets Groups Projects
Commit 8970c3a3 authored by Hietanen Olli's avatar Hietanen Olli
Browse files

Luokkien hienosäätöä

parent 19d4907a
No related branches found
No related tags found
No related merge requests found
package liiga;
import java.util.List;
public class Joukkueet {
......@@ -13,10 +14,11 @@ public class Joukkueet {
//kommentti
}
public void lisaa(Joukkue joukkue) throws SailoException {
if (lkm >= alkiot.length) throw new SailoException("Liikaa alkioita");
alkiot[lkm] = joukkue;
lkm++;
public void lisaa(Joukkue joukkue){
if (lkm < alkiot.length) {
alkiot[lkm] = joukkue;
lkm++;
}
}
......@@ -35,12 +37,25 @@ public class Joukkueet {
public int getLkm() {
return lkm;
}
public List<Joukkue> getJoukkue(int i) {
List<Joukkue> loydetyt = new Arraylist<Joukkue>();
for (Joukkue joukkue : alkiot)
if (joukkue.getID() == i ) loydetyt.add(joukkue);
return loydetyt;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Joukkueet joukkueet = new Joukkueet();
Joukkue borussia = new Joukkue(1, "Borussia M.Gladbach");
Joukkue augsburg = new Joukkue(2, "Augsburg");
joukkueet.lisaa(borussia);
joukkueet.lisaa(augsburg);
System.out.println(joukkueet.getJoukkue(1));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment