Skip to content
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

Changes in Die class. Under upValue #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions debugger_lab_answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Debugger Lab Answers
###Date:1/29/15
Concepcion Sosa

**Question 1:**
The reason why `cutoff` is not a parameter to the method `playTurn` in the `PigGame` class is because `cutoff` is the constructor.

**Question 2:**
The following code would print out 0.0.

**Question 3:**
This statement can be moved to the playTurn method. In the playTurn method, the statement would go within the` if` statement that is within the `while` statement.

**Question 4:**
Based on my current understanding, I think that the problem(s) might be located in the Die class. i think everything else should be normal and run properly.

**Question 5:**
The problem was within the Die class. Under the `public void roll()`, the upValue was `((int)Math.random()*6)+1` which was causing a problem. It would change the number into an integer. However, using the random function, the number it gives us is between 0 & 1. So changing that decimal into an integer would not be helpful because it rounds down. (Random function gives me .09, changes it into an integer which would be 0 +1, which would always be 1.) Solution, I decided to re-write it as `(int)((Math.random() * 6) + 1)`, which allows the math random function to be multiplied by 6 and added together with 1, which then finally gets changed into an integer.

**Question 6:**
For the number 10: 100, 14, ~7.1425.
For the number 15: 104, 15, ~6.933334. For the number 20: 103, 12, ~8.583334. For the number 25: 101, 9, ~11.22221.
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 @@ -9,7 +9,7 @@ public class Main
public static void main(String[] args)
{
// Create a new game with a cutoff of 18
PigGame g = new PigGame(18);
PigGame g = new PigGame(25);

// Run one game
g.playGame();
Expand Down