diff --git a/Herd.java b/Herd.java index bf6a527..6647d5a 100755 --- a/Herd.java +++ b/Herd.java @@ -25,6 +25,7 @@ private ArrayList herd; private Cow[] parents; private Cow[] offspring; + private int selection; private Herd() { @@ -62,6 +63,16 @@ if (c != null) herd.remove(c); } + public void select(int id) + { + selection = id; + } + + public int selected() + { + return selection; + } + public void setParent(int id) { Cow p = getCow(id); @@ -122,12 +133,13 @@ //TODO Test the serialization code! - public void saveHerd(String filename) + public static void saveHerd(String filename) { + if (singleton == null) return; try { FileOutputStream fileOut = new FileOutputStream(filename); ObjectOutputStream out = new ObjectOutputStream(fileOut); - out.writeObject(this); + out.writeObject(singleton); out.close(); fileOut.close(); } catch (IOException i) { @@ -137,7 +149,7 @@ public static void loadHerd(String filename) { - Herd singleton = null; + singleton = null; try { FileInputStream fileIn = new FileInputStream(filename); ObjectInputStream in = new ObjectInputStream(fileIn); @@ -151,7 +163,7 @@ } } - public void resetHerd() + public static void resetHerd() { singleton = null; }