Last week, two of the discussion questions were:+
-6 xxxxx
-4 xxxxxxxxx
-2 xxxxxxxxxxxxxx
0 xxxxxxxxxxxxxxxxx
2 xxxxxxxxxxxxxx
4 xxxxxxxxx
6 xxxxx
Simulate an object moving six times.
\\Dragon\cls_compSci\cs110\Histogram folder (or download
the Histogram zip file) to your own space. Open
the histogram project and edit the file
HistogramLab.java.
As you do so, remember to write appropriate
comments that describe the purpose of the code you are about to
write (what you are trying to accomplish) before writing it.
Coin class to learn how to construct a coin using
the default Coin constructor. Then construct an integer variable
to represent the object's location. Initialize it to 0.
Coin class
documentation to learn how to toss a coin and how to determine whether
the tossed coin is showing heads or tails. Modify your program to toss the
coin six times. Each time you toss the coin, update the location variable
to reflect a move to the right if the coin comes up heads, or a move to the
left if the coin comes up tails.
Add multiple runs.
minusSixCount,
zeroCount, etc. Be sure to initialize each of them to 0. (Question:
how many integer variables will you need to represent all of the possible
final locations?)
NUM_ITERATIONS
that you should use instead of "hard-coding" the number 1000 throughout
your code.)
NUM_ITERATIONS times, print the
number of times the fish ended up in each of the possible final locations.
Run your program several times to test it. Do your results seem to make sense?
You may wish to double-check that the various counts add up to 1000.
Draw a histogram.
DisplayableTable
class documentation to learn how to call the
add
method. Note that there are two methods named add,
both of which expect three parameters. The first
method expects a Color to paint the cell, the cell's
row, and the cell's column. The second add method expects a
String of
text to put in the cell and the cell's row and column.
The code you uncommented contained an example of each
add method.
add
call to add the appropriate number of red blocks for that
row of the histogram. Each red block will go in a new column.
Test your program.
NUM_ITERATIONS set to 10, then several times with NUM_ITERATIONS
set to 20 and 100. How does the behavior change as the number of iterations
changes? Why?
main method that said what
the program would do once it was written.
Print and save your modifications.
HistogramLab.java to accurately
describe the purpose and behavior of the class from a user's perspective.
Focus on what the program does, rather than how it does it.
Include your name and the date as well as the names of anyone from whom you
received help. Providing proper documentation is an important step towards
writing well-structured and reusable programs.
After you have completed this lab and the More Fish! mini-lab, you can start work on Programming Project #3 (due at the beginning of Lab 4).
+These questions came from the Advanced Placement Computer Science Marine Biology Simulation Case Study, available from the College Board.