diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..1cd3e15 --- /dev/null +++ b/Answers.md @@ -0,0 +1,39 @@ +Anna Lamoureux + +Lab 2 + +Pig Game Answers + + + +1. `cutoff` isn't a parameter to the method `playturn` because `cutoff` has already been initialized and does not need to be passed a variable. There is no need to change `cutoff`. +2. The code would print out `0.0` because by coding `ScoreSheet s = new ScoreSheet()` you are referencing a new, and therefore blank ScoreSheet. In ScoreSheet.java, in `getTurnAverage()` it states that if the number of turns is 0, which it would be on a blank score sheet, then return 0.0 . +3. `numBusts` where it is located is simply assuming (correctly) that if the score of a turn was equal to 0, that they had a bust. Instead of its current location, `numBusts` could be moved to the playTurn class after the program detects a rolled 1 and therefore a bust. You could rewrite the code as the code in (Figure a). +4. The program is not printing out anything, so my thought is that the program is stuck in an infinite loop, probably as a result of a point where a variable isn't being incremented. The scoresheet doesn't seem to have any problems by just looking at the code. +5. By watching the values of upValue, score, numTurns, and numBusts, it appears that every single time the computer rolls, it rolls a 1, which only increments numBusts, and numTurns while the score stays at 0 and therefore will continue in the infinite loop of the while the score is less than 100 and turn score is less than 18. The way to correct this mistake is to move the open parenthese from before `(int)` to after to make the line of code looks like that in (Figure b). +6. The average number of turns for cutoff values: 10 = 6.4375, 15 = 3.8889, 20 = 8.4167, 25 = 7.8462 + + +Figure a + +``` +while(!rolledOne && score < cutoff && score + s.getScore() < 100) + { + d.roll(); + if (d.getUpValue() == 1) + { + score = 0; + rolledOne = true; + numBusts += 1; + } + else + score = score + d.getUpValue(); + } +``` + +Figure b + +``` +upValue = (int)(Math.random() * 6) + 1; +``` + diff --git a/src/Die.java b/src/Die.java old mode 100755 new mode 100644 index 6f3a8e4..2ca26c3 --- a/src/Die.java +++ b/src/Die.java @@ -22,7 +22,7 @@ public Die() */ public void roll() { - upValue = ((int)Math.random() * 6) + 1; + upValue = (int)(Math.random() * 6) + 1; } /** diff --git a/src/Main.java b/src/Main.java old mode 100755 new mode 100644 index ff2edf8..4a8ad72 --- a/src/Main.java +++ b/src/Main.java @@ -19,4 +19,4 @@ public static void main(String[] args) System.out.println(g.getNumTurns()); System.out.println(g.getTurnAverage()); } -} \ No newline at end of file +}