Squirrel
Your task for this exercise will be to answer questions
about a Java program excerpt that models two different types of
Robotic Squirrel. The code consists of three Java
classes. File SquirrelManager.java contains the class
with the harvest
method that creates Robotic Squirrel objects and calls
methods on these objects. SquirrelSimplex.java and
SquirrelSapiens.java contain the classes that model the
two different types of Robotic Squirrel.
To start, read each of the class comments to get a feel
for what they each do.
Download files: SquirrelManager.java, SquirrelSimplex.java, SquirrelSapiens.java
Areas: Introduction to classes and objects.
Download files: SquirrelManager.java, SquirrelSimplex.java, SquirrelSapiens.java
Areas: Introduction to classes and objects.
|
|
SquirrelManager.java |
|
View full source |
|
|
SquirrelSimplex.java |
|
View full source |
|
|
SquirrelSapiens.java |
|
View full source |
| Question 1 |
| Open up the full source of SquirrelSimplex.java. At what line number is the variable numHazelnuts declared? |
| Question 2 |
| Can methods outside class SquirrelSimplex access numHazelnuts? |
| Question 3 |
| In SquirrelManager.java, how many objects of type SquirrelSimplex are instantiated? |
| Question 4 |
| How can we find out how many hazelnuts are currently in chip's reservoir? |
| Question 5 |
| After chip's initial picking of hazelnuts, but before any are extracted, that is, at line 22 of SquirrelManager.java, how many hazelnuts does chip have? |
| Question 6 |
| How many hazelnuts does dale have after he was first told to pick hazelnut? |
| Question 7 |
| On lines 35 and 36 of SquirrelManager, does the output appear on the same line or on different lines? |
| Question 8 |
| For the statement
System.out.println(chip.getNumHazelnuts());
found at line 36 of SquirrelManager.java, what is
the output? |
| Question 9 |
| Open up SquirrelSapiens.java. In the report method, hazelnutPrice, numHazelnuts, and totalValue are not in quotes. Why not? |
| Question 10 |
| What is the output to the screen after the harvest method in SquirrelManager.java has executed? |
