Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -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;
```

2 changes: 1 addition & 1 deletion src/Die.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Die()
*/
public void roll()
{
upValue = ((int)Math.random() * 6) + 1;
upValue = (int)(Math.random() * 6) + 1;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Main.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public static void main(String[] args)
System.out.println(g.getNumTurns());
System.out.println(g.getTurnAverage());
}
}
}