summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java b/src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java
index c09893e..fbe150a 100644
--- a/src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java
+++ b/src/de/fhswf/in/inf/java1/aufgabe8/Lottery6OutOf49.java
@@ -16,9 +16,11 @@ import java.util.List;
public class Lottery6OutOf49
{
- private ArrayList<Integer> lotteryNumbers = new ArrayList<>(49);
+ private static final int MAX_NUMBER = 49;
- private ArrayList<Integer> lastDraw = new ArrayList<>(6);
+ private ArrayList<Integer> lotteryNumbers;
+
+ private List<Integer> lastDraw;
private Integer superzahl;
@@ -28,13 +30,12 @@ public class Lottery6OutOf49
*/
public Lottery6OutOf49()
{
- for (int i = 1; i <= 49; i++)
+ lotteryNumbers = new ArrayList<Integer>(MAX_NUMBER);
+
+ for (int i = 1; i <= MAX_NUMBER; i++)
{
lotteryNumbers.add(i);
}
-
- nextDraw();
-
}
/**
@@ -43,17 +44,9 @@ public class Lottery6OutOf49
*/
public void nextDraw()
{
- List<Integer> tmp = FloydAndBentley.sample2(lotteryNumbers, 7);
-
- superzahl = tmp.get(tmp.size() - 1);
-
- lastDraw.clear();
-
- for (int i = 0; i < 6; i++)
- {
- lastDraw.add(tmp.get(i));
- }
+ lastDraw = FloydAndBentley.sample(lotteryNumbers, 7);
+ superzahl = lastDraw.remove(lastDraw.size() - 1);
lastDraw.sort(null);
}
@@ -64,6 +57,10 @@ public class Lottery6OutOf49
*/
public List<Integer> getLastDraw()
{
+ if (lastDraw == null)
+ {
+ throw new IllegalStateException("First needs a sraw.");
+ }
return Collections.unmodifiableList(lastDraw);
}
@@ -74,6 +71,10 @@ public class Lottery6OutOf49
*/
public Integer getSuperzahl()
{
+ if (superzahl == null)
+ {
+ throw new IllegalStateException("First needs a sraw.");
+ }
return new Integer(superzahl);
}