Skip to content

debugger lab #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Answers

**Question 1:** `cutoff` is not a parameter in the `playTurn` method because it is instantiated by the constructor. Member variables are accessable by methods of the class which contains them.

**Question 2:**

`ScoreSheet s = new ScoreSheet(); System.out.println(s.getTurnAverage()); `

Running this code would print the average score as a double. By call the `getTurnAverage` method right after creating a new ScoreSheet object, the code will print out '0.0' by default.

**Question 3:** The `numBusts` variable could be incremented in the `playTurn` method. In this method, we check the three cases that would end a turn, one of which is rolling a 1. This would be a good place to increment the `numBusts` variable without affecting the results.

**Question 4:** Based on my current understanding of the code I think that the error would lie in the while loops in the `PigGame` class's `playGame` or `playTurn` method. I am fairly certain that the error does not lie in any of the Query methods because they don't change data.

**Question 5:** The problem with the program was that the `roll` method in the `Die` class would always would always give `upValue` '0' because of a type casting error. Because of this `playGame` method in the `PigGame` class would never reach '100' resulting in an infinite loop. To fix the error, I changed the code to:

`upValue = ((int)(Math.random() * 6)) + 1;`

**Question 6:**

10: 5.67

15: 6.44

20: 5.72

25: 6.34