-
Notifications
You must be signed in to change notification settings - Fork 16
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
Assignment 7, Arrays #8
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
compile.on.save=true | ||
user.properties.file=/Users/samuraipanzer/Library/Application Support/NetBeans/8.0.2/build.properties | ||
user.properties.file=C:\\Users\\Ronda\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> | ||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> | ||
<group> | ||
<file>file:/C:/Users/Ronda/Documents/Java/Assignment7/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/DnDDiceRoller.java</file> | ||
<file>file:/C:/Users/Ronda/Documents/Java/Assignment7/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/DiceTower.java</file> | ||
<file>file:/C:/Users/Ronda/Documents/Java/Assignment7/CPT-163-27-F2015-Assignment-7-Array-DiceTower/src/dnddiceroller/Die.java</file> | ||
</group> | ||
</open-files> | ||
</project-private> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,84 @@ | ||
|
||
package dnddiceroller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Dice Tower. | ||
* A Dice Tower is a tool used by serious gamers use to roll many dice at once. | ||
* It looks like this https://www.miniaturescenery.com/Images/PortableDiceTowerLarge.jpg | ||
* An instance of a dice tower is defined by the number panels it contains to help | ||
* provide a more regular distribution of die values. The die bounce from panel to | ||
* panel until they exit the dice tower at the bottom tray. | ||
* A dice tower will accept a collection of dice and reports their results when | ||
* they reach the tray at the bottom | ||
* @author Paul Scarrone | ||
* A Dice Tower is a tool used by serious gamers to roll many dice at once. | ||
* | ||
* An instance of a dice tower is defined by | ||
* the number of panels it contains to help provide a regular | ||
* distribution of die values. | ||
* | ||
* The die bounce from panel to panel until they exit the dice tower | ||
* at the bottom of they tray. | ||
* | ||
* A dice tower will accept a collection of dice and report their results | ||
* when they reach the tray at the bottom | ||
*/ | ||
public class DiceTower { | ||
final int PANEL_COUNT = 3; | ||
List<Die> dice; | ||
|
||
public DiceTower() { | ||
this.dice = new ArrayList(); | ||
} | ||
|
||
public DiceTower(List dice) { | ||
this.dice = dice; | ||
} | ||
} | ||
/** | ||
* | ||
* @author Rhonda Marshall | ||
*/ | ||
public class DiceTower { | ||
private final int PANEL_COUNT = 3; | ||
List<Die> dice; | ||
int trayValue; | ||
private final Boolean debug; // This is for my purposes to debug this progam | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I like the debug flag for the class to help with tracking the output. What this flag really does is change the The rule is if we don't use it we delete it before we close our Pull Request. Because I don't see a way to toggle the classes verbosity without recompiling the code I would say this should have been deleted. |
||
|
||
/** | ||
* DiceTower constructors | ||
* | ||
*/ | ||
public DiceTower() { | ||
this.dice = new ArrayList(); | ||
this.trayValue = 0; | ||
this.debug = false; | ||
} | ||
|
||
public DiceTower(List dice) { | ||
this.dice = dice; | ||
this.trayValue = 0; | ||
this.debug = false; | ||
} | ||
|
||
/** | ||
* getTrayValue accessors method | ||
* | ||
* @return trayValue | ||
*/ | ||
public int getTrayValue() { | ||
|
||
return this.trayValue; | ||
|
||
} // getTrayValue | ||
|
||
/** | ||
* dropDice method will roll each die, the number of panels that are | ||
* in the dice tower | ||
* | ||
* accumulate the trayValue | ||
*/ | ||
|
||
public void dropDice() { | ||
// for each of the die in the array | ||
for (Die theDice : this.dice) { | ||
// roll the dice the number of panels in the tower, PANEL_COUNT | ||
for (int j = 0; j < PANEL_COUNT; j++) { | ||
if (this.debug) System.out.printf("dropDice: Rolling %d\n", j); | ||
theDice.roll(); | ||
} | ||
if (this.debug) { | ||
System.out.printf("dropDice: value is %d\n\n", theDice.getValue()); | ||
} | ||
this.trayValue += theDice.getValue(); | ||
} | ||
|
||
if (this.debug) | ||
System.out.printf("trayValue: value of both dice %d\n\n", this.trayValue); | ||
|
||
} // dropDice | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,51 @@ | ||
package dnddiceroller; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* A Die is a many sided object that when rolled provides a random value from | ||
* 1 through the number of sides on the object. Some dice are 6 sided and have | ||
* the numbers 1-6 on them. Some dice are 20 sided with the numbers 1-20 on them. | ||
* Others are called fudge dice and have the values of -1 0 or +1 | ||
* @author Paul Scarrone | ||
* | ||
* @author Rhonda Marshall | ||
* Oct 19, 2015 | ||
*/ | ||
public class Die { | ||
|
||
} | ||
public int numberOfSides; // number of sides on the dice | ||
public int value; // value generated by a random number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Once AGAIN!! I have forgotten to make these private -----Original Message----- In src/dnddiceroller/Die.java:
Only final fields should ever be public and in most cases they still should be private. We do not want to allow external modification of these after the class instance has been initialized otherwise the class could lose its context without us being able to track that modification. |
||
private final Boolean debug; // for my debugging purposes | ||
|
||
/** | ||
* Constructor | ||
* @param numberOfSides The numberOfSides on the dice | ||
*/ | ||
public Die(int numberOfSides) { | ||
this.numberOfSides = numberOfSides; | ||
this.value = 0; | ||
this.debug = false; | ||
|
||
} // Die constructor | ||
|
||
/** | ||
* The roll methods | ||
* - Calculates a random number between the value | ||
* of one and the Die objects numberOfSides field. | ||
* - Sets the Die objects value field to equal the random number | ||
*/ | ||
public void roll() { | ||
// Create a Random class object | ||
Random randomNumber = new Random(); | ||
this.value = randomNumber.nextInt(this.numberOfSides) + 1; | ||
if (this.debug) | ||
System.out.printf("roll: random number is %d\n", this.value); | ||
} | ||
|
||
|
||
/** | ||
* getValue accessors method | ||
* @return The Die objects value | ||
*/ | ||
public int getValue(){ | ||
return this.value; | ||
} // getValue | ||
|
||
} // Die class | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,60 @@ | ||
|
||
package dnddiceroller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Paul Scarrone | ||
* @author Rhonda Marshall | ||
*/ | ||
public class DnDDiceRoller { | ||
|
||
/** | ||
* Try out your dies and dice tower | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
for(int i = 0; i< 1000; i++){ | ||
int d6 = test_oneD6(); | ||
if(d6 != -1){ | ||
System.out.println("Die Test Failed with Value: " + d6); | ||
} | ||
int tower = test_diceTowerWithTwoD6(); | ||
if(tower != -1){ | ||
System.out.println("Tower Test Failed with Value: " + tower); | ||
} | ||
} | ||
} | ||
|
||
public static int test_oneD6(){ | ||
Die die = new Die(6); | ||
die.roll(); | ||
int dieValue = die.value(); | ||
if(dieValue >= 1 && dieValue <= 6){ | ||
return -1; // Means the die value is outside its bounds for a d6 | ||
}else{ | ||
return dieValue; | ||
} | ||
} | ||
|
||
public static int test_diceTowerWithTwoD6(){ | ||
List<Die> dice = new ArrayList(); | ||
dice.add(new Die(6)); | ||
dice.add(new Die(6)); | ||
DiceTower tower = DiceTower(dice); | ||
tower.dropDice(); | ||
int trayValue = tower.trayValue(); | ||
if(trayValue >= 2 && trayValue <= 12){ | ||
return -1; // means the die value is outside the bounds of 2 d6 | ||
}else{ | ||
return trayValue; | ||
} | ||
} | ||
|
||
} | ||
/** | ||
* Try out your dies and dice tower | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
System.out.println("Start Test"); | ||
for (int i = 0; i < 1000; i++) { | ||
int d6 = test_oneD6(); | ||
if (d6 != -1) { | ||
System.out.println("Die Test Failed with Value: " + d6); | ||
} | ||
int tower = test_diceTowerWithTwoD6(); | ||
if (tower != -1) { | ||
System.out.println("Tower Test Failed with Value: " + tower); | ||
} | ||
} | ||
System.out.println("End Test"); | ||
} // main method | ||
|
||
public static int test_oneD6() { | ||
Die die = new Die(6); | ||
die.roll(); | ||
|
||
int dieValue = die.getValue(); | ||
if (dieValue >= 1 && dieValue <= 6) { | ||
return -1; // Means the die value is outsides its bounds for a die | ||
} else { | ||
return dieValue; | ||
} | ||
} // test_oneD6 method | ||
|
||
public static int test_diceTowerWithTwoD6() { | ||
List<Die> dice = new ArrayList(); | ||
dice.add(new Die(6)); | ||
dice.add(new Die(6)); | ||
|
||
DiceTower tower = new DiceTower(dice); | ||
tower.dropDice(); | ||
|
||
int trayValue = tower.getTrayValue(); | ||
if (trayValue >= 2 && trayValue <= 12) { | ||
return -1; | ||
} else { | ||
return trayValue; | ||
} | ||
} // test_diceTowerWithTwoD6 method | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should also be
private