diff --git a/debugger_lab_answers.md b/debugger_lab_answers.md new file mode 100644 index 0000000..a732c59 --- /dev/null +++ b/debugger_lab_answers.md @@ -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. diff --git a/src/Die.java b/src/Die.java old mode 100755 new mode 100644 index 6f3a8e4..25645ba --- 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..306a767 --- a/src/Main.java +++ b/src/Main.java @@ -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();