From 6ef5799462fc89d3e7f1c4393724263fb4827f32 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Thu, 29 Jan 2015 15:13:15 -0500 Subject: [PATCH 1/2] Adding this file --- Answers.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Answers.md diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..6b342c5 --- /dev/null +++ b/Answers.md @@ -0,0 +1,30 @@ +## John Ferguson's Answers to Lab 2 +**Question 1:** Why is `cutoff` not a parameter to the method `playTurn` in the `PigGame` class? + +**Answer 1:** The reason `cutoff` is not a parameter to the method `playTurn` in the `PigGame` class becasue `cutoff` lets you know that value at which you stop playing the game. If you set `cutoff` to `playTurn` then you're giving yourself a certain amount of turns and that doesn't work. You don't know how many turns it will take to get to the `cutoff` value. + +**Question 2:** What would the following code print? `ScoreShet s = new ScoreSheet(); System.out.print.ln(s.getTurnAverage());` + +**Answer 2:** This code is printing out the average number of turns played on a new scoresheet that we created. + +**Question 3:** In the `PigGame` class, `numBusts` is inceremeneted in the `playGame` method. Describe how this statement could be moved to another methond in the class without affecting the results. + +**Answer 3:** numBusts can be moved into playTurn without affecting the results. But within playTurn it would have to be placed after rolledOne = true because then we know we rolled a 1 and we busted so now we can add 1. + +**Question 4:** Based on your current understanding of the code, where do you think the problems might be located? Are there portions of the code where you are fairly certain the problems could not possibly be? + +**Answer 4:** Based on my current understanding of the code, I think that the reason the code is stuck in an infinite loop is becasue all we told the code to do is playGame. We didn't give any other information to track any values or numTurns either. So all the code is doing right now is playing the game infinitely. It doesn't know when it's getting to the cutoff value. On the other hand I think there can't be any problems where we created a new game becasue we gave the new game a cutoff value, also the print statements. + +**Question 5:** Describe the problems with the program and the ways you made the program execute correctly. + +**Answer 5:** The problem was in Die.Java. In the upValue loop, the int was in the wrong spot. It was making the random numbers only select from 0 to 1 instead of 1 t0 6 becasue of that. Then I put int infront of the right side so it looked like (int)(Math.random() * 6)+1;. + +**Question 6:** Using the correct program, what are teh average number of turns for cuttoff values 10,15,20,25? + +**Answer 6:** +10 : 11.2 +15 : 5.611111 +20 : 6.4375 +25 : 17.0 + + \ No newline at end of file From 81dd93e3e6ce8ac95c66bea5b380db3f5851c051 Mon Sep 17 00:00:00 2001 From: John Ferguson Date: Thu, 26 Feb 2015 13:24:40 -0500 Subject: [PATCH 2/2] John Ferguson Debugger-Lab done! --- src/Die.java | 2 +- src/Main.java | 2 +- 2 files changed, 2 insertions(+), 2 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..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..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();