6 points for getting output of about 50/50, and thus fairly
representing heads/tails, implementing random number generation,
and using the loop correctly
2 points for validating number of tosses >= 1
2 points for correct output format (includes # tosses and
percentage)
Triangles
10
Correctness (5 points)
3 points for each correct patterns (test sizes = 2, 3, 4)
2 points for validating size >= 2
-3 for using any print statements other than those listed
Style (5 points)
5 points for correct indentation and consistent bracing of loops
Total
20
General comments:
On style: use the same style for loops that you do for methods and conditionals.
If you write:
if () {
...
}
then also write:
do {
...
} while ();
Or, if you write:
if ()
{
...
}
then also write:
do
{
...
}
while ();
We prefer the first of these two examples because it avoids the use of extra
lines.
Some of you used unnecessary variables on the coin toss program because you
were uncomfortable with casting. Please read and understand the section on casting in your textbook. Casting is an important technique
and it is well worth your time to learn it.
For those who did use casting: you do not need to cast both operands of a division to make sure it's not
integer division.
Always print a helpful error message when rejecting invalid input. Also, instead of just using an if statement to reject invalid input and
end the program, use a do-while loop to keep going until you get valid input. See Michael's solution for an example of how this is done.
This is known as data validation.
Printing the result of every coin flip will overwhelm users, making them wade through too much unnecessary
output to get to the desired output. (Try it for 10000 flips.) Be informative, but be concise as well.