From 468675c06f3136af5569fbeb7556631e2ea778a0 Mon Sep 17 00:00:00 2001 From: Hailey Kester Date: Thu, 29 Jan 2015 15:11:33 -0500 Subject: [PATCH 1/2] Adding Debugger-lab answers --- Answers.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Answers.md diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..5f02281 --- /dev/null +++ b/Answers.md @@ -0,0 +1,33 @@ +# Hailey Kester CSCI 121 1/29/15 +## Debugger Lab + +**Question 1:** Why is cutoff not a parameter to the method playTurn in the PigGame class? + +Cutoff is not a parameter to the method playTurn in the pigGame class because cutoff is used to tell you which value to stop playing the game at. If the cutoff was a parameter, then you would be giving yourself a set value as to when you stop playing the game and you can't do that because we don't know how many turns it will take to finish the game. + +**Question 2:** What would the following code print? +``` +ScoreSheet s = new ScoreSheet(); System.out.println(s.getTurnAverage( )); +``` + +The following code would create a new score sheet and it would print out the average number of turns it take to finish the game on the new score sheet. + +**Question 3"** In the `PigGame` class, `numBusts` is incremented in the `playGame` method. Describe how this statement could be moved to another method in the class without affecting the results. + +The statement `numBusts` could be moved to the method `playTurn` class after `rolledOne = true;` because we need to know if we rolled a one in order to know if we busted, this way if `rolledOne = true` then we know we rolled a one and we also know that we busted. We can then see the number of turns we rolled a one. + +**Question 4:** Based on your current understanding of the code, where do you think the problem(s) might be located? Are there portions of the code where you are fairly certain the problem(s) could not possibly be? + +Based on my current understanding of the code, I think that the problem is that we are giving a cutoff value of 18, but we have nothing in the code that is tracking the number of turns that we have taken. Therefore, the code is going to continue to run infinitely because it doesn't know when it gets to the cutoff value of 18 so it is going to continue playing the game. I think the print functions and the `new PigGame` functions are not where the problem(s) are. + +**Question 5:** Describe the problem(s) with the program and the way(s) you made the program execute correctly. + +The problem was in the `Die.java`, where the upValue line where the `upValue = Math.random`, the `(int)` was missed placed and was giving us just a value between 0 and 1. After figuring out this problem, I moved the `(int)` to be outside of the Math.random part in order for the function to compute an integer, so the new line came out to be `upValue = (int)(Math.random() * 6 ) + 1;` and then the program stopped looping infinitely. + +**Question 6:** Using the correct program, what are the average number of turns for cutoff values 10, 15, 20, and 25? + +The average number of turns for the cutoff value of 10 came out to be `9.090909090909092`. +The average number of turns for the cutoff value of 15 came out to be `7.285714285714286`. +The average number of turns for the cutoff value of 20 came out to be `10.2`. +The average number of turns for the cutoff value of 25 came out to be `17.0`. + From d53c3428a2274bb5eb5cdc0e74e72155f2e8feb6 Mon Sep 17 00:00:00 2001 From: Hailey Kester Date: Thu, 26 Feb 2015 12:17:20 -0500 Subject: [PATCH 2/2] Debugger-Lab Submitted --- src/Die.java | 2 +- src/Main.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) mode change 100755 => 100644 src/Die.java mode change 100755 => 100644 src/Main.java diff --git a/src/Die.java b/src/Die.java old mode 100755 new mode 100644 index 6f3a8e4..494361f --- 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..ce9b80b --- 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(); @@ -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 +}