diff --git a/Cow.java b/Cow.java index ecad563..5a11a43 100755 --- a/Cow.java +++ b/Cow.java @@ -87,7 +87,11 @@ return generation; } - + public int[] getParents() + { + return parents; + } + public String getName() { return name; diff --git a/Cow.java b/Cow.java index ecad563..5a11a43 100755 --- a/Cow.java +++ b/Cow.java @@ -87,7 +87,11 @@ return generation; } - + public int[] getParents() + { + return parents; + } + public String getName() { return name; diff --git a/Herd.java b/Herd.java index ae3ecdf..200d05a 100755 --- a/Herd.java +++ b/Herd.java @@ -79,15 +79,25 @@ public String checkBreeding() { - //TODO + //check both parents present + if (parents[0] == null) return "You haven't selected a bull!"; + if (parents[1] == null) return "You haven't selected a cow!"; + //check age difference (max 3 generations) + if (Math.abs(parents[0].getGeneration() - parents[1].getGeneration()) > 3) + return "The age difference between the parents is too great!"; + //check for siblings + if (parents[0].getParents()[0] == parents[1].getParents()[0] && + parents[0].getParents()[1] == parents[1].getParents()[1]) + return "You cannot let siblings mate!"; return "OK"; } public void breed() { - //TODO - //randomly generate either one or two offspring - //breed the parents to create the offspring + if (checkBreeding() != "OK") return; + int noffs = random.nextInt(2)+1; + offspring[0] = new Cow(parents[0], parents[1]); + if (noffs == 2) offspring[1] = new Cow(parents[0], parents[1]); } public void keepChild(int id)