From a8ef56c72e453d62108150598622de6ba70a408a Mon Sep 17 00:00:00 2001 From: Josh Russett Date: Tue, 3 Feb 2015 13:13:53 -0500 Subject: [PATCH 1/2] Answers.md from the previous lab that I failed to commit. (Hopefully I will learn my lesson) --- Answers.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Answers.md diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..dbdef69 --- /dev/null +++ b/Answers.md @@ -0,0 +1,21 @@ +``` +Josh Russett +CSCI II Lab +27 Jan 2015 +``` +#Debugger Lab Answers + +####Question 1: +The variable `cutoff` is not a parameter for the `playTurn` method because `cutoff` is assigned as private copy, local only to the `PigGame` class, of the cutoff value, `cutoffValue`. This in turn eliminates the redundancy and need to pass the `cutoff` variable to the `playTurn` method each time. + + +####Question 2: +The code: `ScoreSheet s = new ScoreSheet(); System.out.println(s.getTurnAverage());` would simply return the value `0.0` as the code intializes a new `ScoreSheet` object referenced by `s`, and then prints the query for the average (`s.getTurnAverage()`), which, if `numTurns == 0`, simply returns `0.0`. + +####Question 3: +In the `playGame` method, the body of the while-loop checks the score of the turn played and increments `numBusts` by one if `score == 0`; rather than increment `numBusts` in that while-loop, one could instead incrememt `numBusts` immediated after a 1 is rolled in the `playTurn` method. + +####Question 4: +I believe, with my current understanding of the code, that the problem is most likely going to be in the **PigGame.java** portion of this program, especially the `playTurn` method, as it is where "everything is happening" in the sense that the most complicated part of the pig game (rolling dice multiples times for a turn score) is coded. Another possibility is the **Die.Java**, as the `Die` class looks a little strange in the implementation. As for the rest of the files, **Main.java** looks pretty straightforward as it is only calling the other classes and **ScoreSheet.java** only records, stores and returns values. + + \ No newline at end of file From d840e3b34aa83ba0401b7391bf13b450d332999c Mon Sep 17 00:00:00 2001 From: Josh Russett Date: Sun, 15 Feb 2015 22:27:28 -0500 Subject: [PATCH 2/2] Final Commit; the lab should be complete. --- Answers.md | 13 ++++++++++++- src/Die.java | 2 +- src/Main.java | 25 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 11 deletions(-) mode change 100755 => 100644 src/Die.java mode change 100755 => 100644 src/Main.java diff --git a/Answers.md b/Answers.md index dbdef69..6959fe5 100644 --- a/Answers.md +++ b/Answers.md @@ -18,4 +18,15 @@ In the `playGame` method, the body of the while-loop checks the score of the tu ####Question 4: I believe, with my current understanding of the code, that the problem is most likely going to be in the **PigGame.java** portion of this program, especially the `playTurn` method, as it is where "everything is happening" in the sense that the most complicated part of the pig game (rolling dice multiples times for a turn score) is coded. Another possibility is the **Die.Java**, as the `Die` class looks a little strange in the implementation. As for the rest of the files, **Main.java** looks pretty straightforward as it is only calling the other classes and **ScoreSheet.java** only records, stores and returns values. - \ No newline at end of file + +####Question 5: +The problem with the program was that the `Die` class did not generate the proper random numbers, rather it just spewed a buch of 0's out. To fix the problem, I made sure that the typcasting of the `roll` method was set to Integer, and then the program worked correctly. + +####Question 6: + +|Cutoff Value| Average Number of Turns| +|--|--| +| 10 | 6.0588235294117645 | +| 15 | 6.0 | +| 20 | 11.222222222222221 | +| 25 | 11.444444444444445 | \ No newline at end of file diff --git a/src/Die.java b/src/Die.java old mode 100755 new mode 100644 index 6f3a8e4..2ca26c3 --- 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..a107f26 --- a/src/Main.java +++ b/src/Main.java @@ -8,15 +8,22 @@ public class Main { public static void main(String[] args) { - // Create a new game with a cutoff of 18 - PigGame g = new PigGame(18); + int[] values = {10, 15, 20, 25}; - // Run one game - g.playGame(); - - // output the results - System.out.println(g.getScore()); - System.out.println(g.getNumTurns()); - System.out.println(g.getTurnAverage()); + for (int i = 0; i < values.length; i++){ + // Create a new game + PigGame g = new PigGame(values[i]); + + // Run one game + g.playGame(); + + // Output the results + //System.out.println(g.getScore()); + //System.out.println(g.getNumTurns()); + //System.out.println(g.getTurnAverage()); + + //My Output + System.out.println("| " + values[i] + " | " + g.getTurnAverage()+ " |"); + } } } \ No newline at end of file