CSCI 235 Spring 2020
Data Structures and Software Design
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook
Homework

Policies
Advice
College
    Policies

Notes
Programs
Tutorials

CSCI 125
CSCI 255
Others

Admin

Homework 5

Details

The next two assignments will be related to the Foxes And Rabbits simulation. In this assignment you will (a) improve the design of the simulation and (b) add a third creature. In the next assignment you will improve the GUI. You can see an example of what a finished Homework 6 might look like by downloading and running FoxesAndRabbitsAndSasquatch.jar. You might notice that there is only 1 Sasquatch and he eats everything around him. As you can see by running this, he doesn't really affect the simulation much.

Start with the code in the FoxesAndRabbits2020 project.

  1. Fork the repository at https://bitbucket.org/ferzle/foxesandrabbits2020 by logging into your BitBucket account, going to the URL above, clicking the large + on the left side of the page and selecting Fork this repository, and make sure to click the box for This is a private repository, and click Fork repository.
  2. Import it into Eclipse: Click File-->Import..., select Git-->Projects from Git, then choose Clone URI, enter the URL from YOUR fork of the project (which you can get by clicking the Clone link) in the URI field, and click Finish.

Part A

Add the Animal superclass of Fox and Rabbit as suggested in the various exercises in the textbook (through about 12.50). Make sure you move as many methods/fields up to Animal as you can (and as make sense). Also make sure you have removed every reference to Fox and Rabbit you can throughout the code. (Hint: you probably can't remove the references within Fox and Rabbit since they need to know what type of animal they are interacting with. You also can't remove them in the populate method. You can remove them from simulateOneStep, however. You also should now have one list of Animals instead of lists for each of Fox and Rabbit. There are other places to remove them from as well.)

Note that the simulation should run exactly as it did before you made the changes, so verify that it does so. The difference is that it is (hopefully) better designed so that it is easier to maintain the code and you will be able to more easily complete Part B.

Part B

For this part of the assignment you will improve the Foxes And Rabbits simulation by adding another creature. Do not read or attempt this part until you have finished Part A since it might confuse or mislead you.

The third creature must not be another animal (i.e. it cannot be a subclass of Animal), and you should try to think of a creature that will affect the simulation in some significant way. You should perform some of the suggestions from the textbook to create an Actor class, refactor the code accordingly, and add your third creature. Some ideas for creatures include a human, a virus, a dragon, weather, fire, etc. It must act different than both the fox and the rabbit in some significant way (e.g. never dies, doesn't breed, kills everything within 1 or 2 squares (but as Sasquatch demonstrates, having one such creature is boring), kills everything in its row and column, teleports, etc.).

For more of a challenge (and bonus points), do any of the following:

  • Make the drawing of the simulation a bit fancier. You can draw actual foxes and rabbits, or use little circles for bunnies and triangles for foxes or something similar.
  • Add a fourth creature that is significantly different than the others.

Tips (for both parts):

  • Use what you have learned about inheritance and polymorphism to implement this properly.
  • Do not just sit down and start programming--it will be much easier to implement if you first sit down and think about design.
  • The random number generator for the Foxes and Rabbits simulation is set up so that it always generates the same sequence of numbers. This can be helpful when debugging, but it annoying when your simulation seems to always end after 170 steps (for instance) because all of the Foxes have died. To make it run different every time, go to Randomizer.java and change line 18 to:
    private static final Random rand = new Random();
    That is, just remove SEED from the call to the constructor.
    The documentation in that class suggests an alternative: Change the field useShared to false. I don't like that solution as much (because it creates new random objects all of the time instead of reusing one), but that will probably work as well.

Handing it in (for both parts)

Hand it in as follows (points will be deducted if you deviate from these instructions!):
  1. Fill in the details of the MyGrade-HW5a.txt or MyGrade-HW5b.txt file (depending on which part you are submitting) in your project (double-click it to edit it) with your self-evaluation. Make sure you provide the total and a justification for each category. Your justification should be more than one or two sentences but less than half a page. For part B, include a very brief description of the creature you added in MyGrade-HW5b.txt.
  2. In Windows Explorer, right click on the Foxes and Rabbits 2020 folder and select Send to-->Compressed (zipped) folder.
  3. Name the zipfile whatever you wish and make sure it is a .zip file and not some other format.
  4. Use Webhandin with assignment 235-HW5 to submit the zipfile you just created.

Grades (For Part A)

Your grade will be based on:

CriteriaPoints
Correctness10
Design10
Style/Documentation10
Total30
Possible deductions
  • Not following the directions for how to zip up and submit code. (-1 or -2)
  • MyGrade-HW5a.txt not filled out or lacks enough detail. (-2 or -3)
Examples of things I will be looking for as I grade
  • Correctness: Does it compile (0 points if it doesn't!)? Does it still work as expected?
  • Design: Did you correctly refactor the code? Proper use of Animal throughout? Removal of Fox/Rabbit where possible (replaced with Animal)? Removal of code/field duplication wherever possible? Did you over-refactor? (That's probably not a word, but I mean did you move too much to Animal so that Fox and Rabbit are more similar than they are supposed to be?)
  • Style/Documentation: Does your Animal class contain complete Javadoc documentation? Is your code readable, with loops properly indented, etc. (Hint: CTRL-SHIFT-F in each class before you submit it.)?

Grades (For Part B)

Your grade will be based on:

CriteriaPoints
Correctness10
Design10
Style/Documentation10
Total30
Bonus5

Possible deductions
  • Not following the directions for how to zip up and submit code. (-1 or -2)
  • MyGrade-HW5b.txt not filled out or lacks enough detail. (-2 or -3)
  • No description of 3rd creature in MyGrade-HW5b.txt (-1 or -2)

Here is a more detailed breakdown of the grading criteria for Part B:


third creature works 2
third is not animal 3
third different than others 2
program runs 3
Total Correctness 10

Actor class implemented and used 2
fields and methods properly placed in hierarchy 2
no unnecessary special code (e.g. in simulateOneStep) 2
cohesion (no weird methods or fields) 2
no unnecessary code duplication 2
Total Design 10

Javadoc for all classes/methods 3
documentation in code where necessary 2
good class, method, field names 2
code organized, extraneous code removed 3
Total Style and Documentation 10

4th unique creature (bonus) up to 2
improved graphics (bonus) up to 3
Total Bonus up to 5

Here are some of the common mistakes related to the main grading criteria that past students have made:
  • The fact that everything will probably implement location stuff the same way may suggest an abstract class.
  • Your third creature is virtually identical to Animal--it has all of the same fields and methods. Thus you didn't really implement something different than an Animal, you just put is somewhere else in the hierarchy and duplicated code.
  • Your third creature is almost identical to Rabbit and/or Fox.
  • Special cases for your third creature in simulateOneStep may indicate a design problem.
  • Since your creature can't die, why is setDead in Actor?
  • Since your creature can't age, why are the age related methods in Actor?
  • Don't leave old documentation in your files. For instance, if you copy a class, update all of the documentation. Add your name to classes you created. Do not include the name of the textbook authors in classes you created.
  • Remember to use Javadoc comments for every class and every method.