Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
 Western Oregon University     Page 1 of 2 
CS-162 PreLab #4: Fox and Rabbit Simulation 
General 
At the top of the every document that you create (word processing files or source 
files) include: 
/** 
 * Description of the class or document.  
 *  
 * @author YOUR NAME 
 * @version CS161 Lab #, mm/dd/yyyy (replace with the last edit date)  
*/ 
 
The primary purpose of each pre-lab is to help you prepare to be an active 
participant during the lab sessions, and to be ready to discuss and understand the 
material presented in lectures. This is why late submissions are NOT accepted as that 
defeats the primary purpose of the prelab. However, as these are done prior to class 
discussions, PRE-LABS are not graded on correctness of your answers, but on 
whether you have shown a reasonable attempt at investigating and trying to solve 
the problem. 
  
Please feel free to bring up questions during your lecture class about material in the 
prelabs that you don’t understand or where not able to complete correctly.  We will 
devote some of the lecture time to answering these questions. Prelabs are part of a 
flipped classroom model where you are responsible for studying and learning the 
majority of the easier to understand material so that we can focus on the more 
difficult concepts during the lecture time that is available. 
 
Prelabs are NOT collaborative assignments; they are to be done individually. 
Academic plagiarism policies apply and are enforced.  
 
Concepts 
This lab will extend your experience with designing and programming using Java Inheritance.  
This lab will focus reading and understanding an existing, complex application (Fox and Rabbit 
Simulation). 
 
Background 
Read chapter #10 and review the online tutorials on inheritance.  Study the example in chapter 
#10 that discusses the implementation of the Fox and Rabbit Simulation.  Try to do several of 
the exercises suggested in the text.  
 
Assignment 
This prelab is going to involve both reading a lot of existing code for understanding, modifying 
the code and running experiments with the resulting program.  You will write up the results of 
your explorations.  Do all of this prelab with the foxes-and-rabbits-v2 project. 
 
NOTE FOR THIS LAB ONLY: You do not need to build JUnit tests for this prelab unless you feel it 
will assist you in completing the lab in some way.  You also only need to write JavaDocs for any 
new methods that you create. 
 
1. (10.14) Does increasing the maximum age for foxes lead to significantly higher numbers of 
foxes throughout a simulation, and is the rabbit population more likely to be reduced to zero as 
a result? 
 
 Western Oregon University     Page 2 of 2 
CS-162 PreLab #4: Fox and Rabbit Simulation 
2. Try modifying the isViable() method in FieldStats so that the simulation continues as long as 
there is anything left alive.  What happens as a result of this? 
( return nonzero > 0; ). What additional feature might be added to make this more realistic? 
 
3. (10.16) Experiment with different sizes of the field (You can do this with the second 
Simulator constructor).  Does the size of the field affect the likelihood of species surviving? 
 
4. (10.19) Currently, a fox will eat at most one rabbit at each step. Modify the findFood 
method so that the rabbits in ALL adjacent locations are eaten at a single step.  What is the 
impact of this change on the long runs of the simulation? 
 
5. (10.45) Move the canBreed method from Fox and Rabbit to Animal and rewrite it as shown in 
the Code 10.8 from the text. Provide appropriate version of getBreedingAge in Fox and Rabbit. 
Are those changes sufficient to recompile the project?  If not, what is missing from Animal (and 
fix it!)? 
 
6. (10.46) Move the incrementAge method from Fox and Rabbit to Animal by providing an 
abstract getMaxAge method in Animal and a concrete version in Fox and Rabbit. 
 
 
 
7. Add one “main” program entry point method to an appropriate class or create a new class. 
Your main should create an instance of the Simulator and start the Simulation in motion.  Then 
run the application from a command prompt directly. 
 
8. Turn in a minimum of 3 questions from the material covered in this preLab. 
 
 
Submission Instructions 
Submit in this prelab via Moodle using the “PreLab #” link. Your assignment MUST be 
uploaded by the assignment due date and time (see Moodle for the time), no 
exceptions or extensions of time are given. Partial credit is given, so submit however 
much of the prelab that you have completed by the due time otherwise both the 
prelab and lab will receive a 0 grade for the week. Moodle will automatically close the 
link at that time.   
 
It is highly recommend you do not wait until the very last minute to submit your 
work. 
 
ALL PRE-LABS are to be submitted as a SINGLE document in PDF format. 
Most modern word processors can now generate a PDF file or you can download free 
utilities to do the conversion (CutePDF for pc’s). Any submissions in any other format 
will not be graded and will not receive credit. 
 
Type your answers when appropriate, or if diagrams are needed you may scan them 
or take a picture and then paste the picture into the document.  For coding 
questions, take one or more screen shots that show the code that you modified or 
created; and take screen shots of the run of your programs showing the outputs.  
Paste anything into your document that demonstrates your investigation and work 
on each of the questions. 
 
In your submission, please mark each of your answers/investigation with the 
question number clearly shown.  Order the questions/answers in your PDF document 
in the same order that they are assigned in the prelab.  If you do not do this, you 
may not get credit for some of your work.