Question: SO I'm completing this project using java. I'm 85% done with my code. and I just need to change/ add some things. things to add
SO I'm completing this project using java. I'm 85% done with my code. and I just need to change/ add some things.
things to add or change are.. ( this will make sense after reading the assignment instructions)
If a wolf falls below 1 lb - it dies.
If the field gets more than 150 rabbits - it is overrun with rabbits, all food is consumed, and the rabbits die.
If a dog is dead print that out for the days information. IE Fluffy is Dead
If all dogs die, or the field becomes unhealthy end the program.
I don't have any constants in my code.
and my program ends after day 7 :( ( it should not do that!)
can anyone help me add these lists I missed on my code that is below
this is the assignment instructions...
Here are the classes and methods you will need to implement to successfully complete this assignment. You may need additional methods ( I expect that you will) but this is what is required:
Class Field // Represents the field where the rabbits live.
A constructor that takes the initial number of rabbits, and the fertility factor.
int numRabbits() // returns the # of live rabbits In the field
Rabbit searchForRabbit() // Returns a rabbit if one is found. The likelihood of findinga rabbit goes up as the number of rabbits in the field goes up.
int getAge() // returns the number of days the field has been in existence.
void rabbitDied() // Notifies the field that a rabbit has died
Boolean isHealthy() // Returns true if the field is healthy
void dayPassed(); // Tells the field a day has passed. Thefield figures out how many new rabbits should be born and adds them to the total. Also increments the count for age.
static void testField(); // A test method that makes sure the tricky bits ( like dayPassed) are working correctly.
Class Wolf // Represents the wolf.
A constructior that takes the name, and initial weight of the wolf.
String getName();
double getWeight();
Boolean isDead(); // Tells us if the wolf is dead or alive
static int numLiveWolves(); // Tells how many wolves are alive.
static int getNumEaten(); // Tells us how many rabbits have been eaten by all wolves.
HuntResults Hunt ( Field fld); // A wolf goes hunting in the field. Updates wolf weight and tells the rabbit is is dead as appropriate. Returns an enum to say what the results were ( no rabbit seen, chased, caught)
Class Rabbit // Represents the rabbit.
A constructor that takes the feet from the hole of the rabbit, and the field that created it
boolean runAwayAndHide( double wolfDistance, double wolfSpeed) // A method to see if the rabbit is caught or not. Returns true if he got away, else returns false.
void isEaten(); // Notifies the rabbit he has been eaten.
Class Simulation // Has the main function sets up the loop, runs the simulation, etc. You should single step the simulation. IE have the user press the enter key to do another days worth of simulation. The output of the program should be similar to the following.
Sample output:
Day 1 100 rabbits in field
Max did not see a rabbit. 4.2 lb
Fluffy chased a rabbit 4.5 lb
Brutus caught a rabbit 5 lb
Total number of rabbits eaten 1
Day 2 99 rabbits in field
Max caught a rabbit. 4.6 lb
Fluffy did not see a rabbit 4.4 lb
Brutus chased a rabbit. 4.9 lb
Total number of rabbits eaten 2
Day 3 100 rabbits in field
Max caught a rabbit 5.0 lb
Fluffy caught a rabbit 4.8 lb
Brutus caught a rabbit 5.3 lb.
Total number of rabbits eaten 5
Additional notes.
I dont want to see any magic numbers in your code. use constants and define them properly.
This program requires the use of an enum. In the driver program, you will use the returned enum to determine what to print about the Wolfs actions that turn. Use a case statement for this.
The program will require both static and member variables, as well as static and member methods.
I have not laid out the driver program. Each day should print out something similar to the output above. Design the program so the user must press the return key after each day to proceed to the next day.
This program is not about how to figure out the Right way to know how far from a hole a rabbit is. Or exactly how the number of rabbits affect the probability of a wolf seeing one etc. Find a way that fits the parameters of the simulation as laid out below.
If a dog is dead print that out for the days information. IE Fluffy is Dead
If all dogs die, or the field becomes unhealthy end the program.
For reference the rules of the simulation.
Rabbits live in a field.
The wolves visit the field once a day to hunt for rabbits.
The likelihood of a dog seeing a rabbit is based on the number of rabbits in the field ( The more rabbits the more likely the wolf is to see one).
If a wolf sees a rabbit he will try to catch and eat it.
The chance of a wolf catching the rabbit is based on how fast the wolf can run, and on how far the rabbit is from the nearest rabbit hole.
All rabbits move at the same speed. The distance a rabbit is from a hole varies as the number of rabbits in the field.
If the wolf does not see a rabbit, he expends 0.1 lb in searching.
If the wolf sees a rabbit, gives chase, and does not catch it he expends 0.2 lb searching
If the wolf catches the rabbit he has a nice dinner and puts on 0.4 lb. ( net after chasing)
Wolves run slower the heavier they get.
Every evening, more rabbits are born. The number born is based on the number of surviving rabbits times the fertility factor of the rabbits.
If a wolf falls below 1 lb - it dies.
If the field gets more than 150 rabbits - it is overrun with rabbits, all food is consumed, and the rabbits die.

The code I've Done...
Field.java
public class Field { //class variables int rabbits; int fertilityFactor; //constructor
public Field(int rabbits, int fertilityFactor) { this.rabbits = rabbits; this.fertilityFactor = fertilityFactor; } //getter method public int numRabbits(){ return rabbits; } /otifiying field rabbit died public void rabbitDied(){ System.out.println("Rabbit died"); rabbits--; } //ishealthy function public boolean isHealthy(){ if(rabbits > 0 && rabbits =150){ rabbits = 0; } return false; } //day passes mathod public void dayPassed(){ int newRabbits = (int) (rabbits * fertilityFactor*0.01); System.out.println("New Rabbits: "+newRabbits); rabbits = rabbits + newRabbits; } //testing method static void testField(){ System.out.println("Working correctly"); } }
Wolf.java
public class Wolf { static int totalWolves = 0; //class variables String name; double weight; static int rabbitsEat=0; //constructor public Wolf(String name, double weight) { this.name = name; this.weight = weight; totalWolves++; } //getter method public String getName() { return name; }
public double getWeight() { return weight; } static int numLiveWolves(){ return totalWolves; } //returns total rabbits eat static int getNumEaten(){ return rabbitsEat; } //hunting rabbit method public String Hunt ( Field fld){ rabbitsEat++; fld.rabbitDied(); this.weight = this.weight - 0.1; return "rabbit found"; } }
Rabbit.java
public class Rabbit { //class variables declared double feet; Field field; //constructor public Rabbit(double feet, Field field) { this.feet = feet; this.field = field; } //checking wolf hunts or not public boolean runAwayAndHide( double wolfDistance, double wolfSpeed){ if(wolfDistance/wolfSpeed > 5){ return false; } return true; } /otitfying rabbit eaten public void isEaten(){ System.out.println("Rabbit eaten"); } }
----------------------------------------------------------------------------------------------------------------------------
Simulation.java
import java.util.Scanner; /** * * @author prmsh */ public class Simulation { public static void main(String args[]){ int day = 0; Scanner sc = new Scanner(System.in); //creating Field and wolf objects Field field = new Field(50,10); Wolf wolf = new Wolf("Max",10); Rabbit rb = new Rabbit(50,field); //simulating hunting while(true){ System.out.println("Day: "+day); System.out.println(wolf.getName() +" chasing a rabbit"); //hunting starts if(rb.runAwayAndHide(100, 30)){ System.out.println(wolf.Hunt(field)); } //printing results System.out.println("Total rabbits eaten: "+Wolf.getNumEaten()); System.out.println("Total rabbits on field: "+field.numRabbits()); //calling next day for rabbits field.dayPassed(); //checking user want to exit System.out.println("Press q to quit"); String choice = sc.nextLine(); if(choice.equals("q")){ break; } day++; } } }
Criteria Ratings Pts Full Marks No Marks Comments and indentation. Proper naming of classes etc. 5.0 pts 5.0 pts 0.0 pts Full Marks No Marks Implemented Field, Rabbit, Wolf, with appropriate methods per the spec. 4.0 pts 4.0 pts 0.0 pts Full Marks No Marks Buil d proper test function in Field 2.0 pts 2.0 pts 0.0 pts Full Marks No Marks Proper use of constants (upper case using final 2.0 pts 2.0 pts 0.0 pts Full Marks No Marks Use of Enum in return from Hunt. Use of case statement to display output. 2.0 pts 2.0 pts 0.0 pts Full Marks No Marks Proper use of Static to get total number of rabbits eaten, OR Number of wolves alive 2.0 pts 2.0 pts 0.0 pts Output that generally matches the specification. Full Marks No Marks 6.0 pts view longer description 6.0 pts 0.0 pts Full Marks No Marks Takes keyboard input for each day in the simulation 2.0 pts 2.0 pts 0.0 pts Chance of seeing a rabbit depends on the number of rabbits in the field Full Marks No Marks 2.0 pts view longer description 2.0 pts 0.0 pts Chasing a rabbit. Wolf speed and distance from hole used. Parameters calculated reasonabley Full Marks No Marks 4.0 pts view longer description 4.0 pts 0.0 pts Full Marks No Marks Fertility of rabbits is reasonable and partial rabbits' are saved to the next day 2.0 pts 2.0 pts 0.0 pts Full Marks No Marks Description of criteriorn 2.0 pts 2.0 pts 0.0 pts
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
