Skip to content

Finished Debugger-Lab #9

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

Open
wants to merge 2 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
32 changes: 32 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
```
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.


####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 |
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
25 changes: 16 additions & 9 deletions src/Main.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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()+ " |");
}
}
}