Get started with java 2 mid-project
This commit is contained in:
parent
db1c656ef5
commit
da0e438ad7
1
Project/.~lock.CIS 217 Project 1 Winter 2021(4).docx#
Normal file
1
Project/.~lock.CIS 217 Project 1 Winter 2021(4).docx#
Normal file
@ -0,0 +1 @@
|
||||
,logen,logen,18.02.2021 09:04,file:///home/logen/.config/libreoffice/4;
|
81
Project/MyDiceGameTest.java
Normal file
81
Project/MyDiceGameTest.java
Normal file
@ -0,0 +1,81 @@
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
/*******************************************
|
||||
* The test class for Chuck
|
||||
*
|
||||
* @author Resendiz
|
||||
* @version February 2021
|
||||
******************************************/
|
||||
|
||||
public class MyDiceGameTest {
|
||||
|
||||
/******************************************************
|
||||
* Test initial values of the constructor
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
GameManager game = new GameManager(6);
|
||||
int credits = game.getDice().getCredits();
|
||||
|
||||
// confirm there is only one copy of Title 1
|
||||
Assert.assertEquals("Game should start with 10 credits",
|
||||
credits, 10);
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test Large
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testLarge() {
|
||||
// confirm large is rolled
|
||||
GameManager game = new GameManager(6);
|
||||
int credits = game.getDice().getCredits();
|
||||
game.getDice().testRoll(new int[]{6, 6, 5});
|
||||
game.getDice().checkLarge();
|
||||
Assert.assertEquals("Dice => (6,6,5): credits should stay the same",
|
||||
game.getDice().getCredits(), credits);
|
||||
|
||||
// confirm large is not rolled
|
||||
GameManager game2 = new GameManager(6);
|
||||
credits = game2.getDice().getCredits();
|
||||
game2.getDice().testRoll(new int[]{1, 2, 3});
|
||||
game2.getDice().checkLarge();
|
||||
Assert.assertEquals("Dice => (1,2,3): credits should decrease by one",
|
||||
game2.getDice().getCredits(), credits - 1);
|
||||
|
||||
// confirm large rolled with three of kind
|
||||
GameManager game3 = new GameManager(6);
|
||||
credits = game3.getDice().getCredits();
|
||||
game3.getDice().testRoll(new int[]{4, 4, 4});
|
||||
game3.getDice().checkLarge();
|
||||
game3.getDice().checkTriplets();
|
||||
Assert.assertEquals("Dice => (4,4,4): credits should increased by one",
|
||||
game3.getDice().getCredits(), credits + 1);
|
||||
|
||||
// confirm large is not rolled with three of kind
|
||||
GameManager game4 = new GameManager(6);
|
||||
credits = game4.getDice().getCredits();
|
||||
game4.getDice().testRoll(new int[]{3, 3, 3});
|
||||
game4.getDice().checkLarge();
|
||||
game4.getDice().checkTriplets();
|
||||
Assert.assertEquals("Dice => (3,3,3): credits should stay the same",
|
||||
game4.getDice().getCredits(), credits);
|
||||
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
* Test Triplets
|
||||
*****************************************************/
|
||||
@Test
|
||||
public void testTriplets() {
|
||||
// confirm triplets is rolled
|
||||
GameManager game = new GameManager(6);
|
||||
int credits = game.getDice().getCredits();
|
||||
game.getDice().testRoll(new int[]{1, 1, 1});
|
||||
game.getDice().checkTriplets();
|
||||
Assert.assertEquals("Dice => (1,1,1): credits should stay the same",
|
||||
game.getDice().getCredits(), credits);
|
||||
|
||||
}
|
||||
}
|
17
Project/MyDie.java
Normal file
17
Project/MyDie.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class MyDie {
|
||||
protected int myValue;
|
||||
protected Random rand;
|
||||
|
||||
public MyDie(){
|
||||
myValue = -1;
|
||||
}
|
||||
|
||||
abstract public void roll ();
|
||||
abstract public int getValue();
|
||||
abstract public void setSeed(int seed);
|
||||
abstract public int compareTo(Object o);
|
||||
|
||||
|
||||
}
|
32
Project/SixDie.java
Normal file
32
Project/SixDie.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.*;
|
||||
|
||||
public class SixDie extends MyDie implements Comparable {
|
||||
|
||||
public SixDie() {
|
||||
// set default values
|
||||
myValue = (int) (Math.random()*6)+1;
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
public void roll () {
|
||||
myValue = rand.nextInt(6) + 1;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
|
||||
// set the random number generator seed for testing
|
||||
public void setSeed(int seed) {
|
||||
rand.setSeed(seed);
|
||||
|
||||
}
|
||||
|
||||
// allows dice to be compared if necessary
|
||||
public int compareTo(Object o) {
|
||||
SixDie d = (SixDie) o;
|
||||
return getValue() - d.getValue();
|
||||
}
|
||||
|
||||
}
|
BIN
Project/notes/CIS 217 Project 1 Winter 2021(4).docx
Normal file
BIN
Project/notes/CIS 217 Project 1 Winter 2021(4).docx
Normal file
Binary file not shown.
95
Project/notes/notes.java
Normal file
95
Project/notes/notes.java
Normal file
@ -0,0 +1,95 @@
|
||||
/* Make a dice game */
|
||||
/*
|
||||
* played with three d6 or d8
|
||||
* bets placed on combinations that can apear on dice
|
||||
*
|
||||
* game begins with 10 credits
|
||||
* rolls cost one credit
|
||||
*
|
||||
* Bets are placed on possible outcomes
|
||||
* Payout increases number of credits by one if that outcome appears
|
||||
*
|
||||
* Large -- total value over 10
|
||||
* Three of a kind -- face value of all dice identical
|
||||
* Two of a kind -- face value of two are identical
|
||||
* So... I guess you need to get at least two in order to gain credits
|
||||
*
|
||||
* sixDie.java is premade and complete. Don't make changes.
|
||||
* *****************DiceCup******************************
|
||||
* create class DiceCup
|
||||
*
|
||||
* Create appropriate private vars for the Following
|
||||
*
|
||||
* an ArrayList of three MyDie objects
|
||||
* credit balance int
|
||||
*
|
||||
* Constructors
|
||||
* public DiceCup ()
|
||||
* instantiate and populate the arraylist
|
||||
* instantiate arraylist of three SixDie or EightDie objects
|
||||
* use loop to assign them to the elements of the arraylist
|
||||
* Initialize credit to 10
|
||||
*
|
||||
* Accessor Methods
|
||||
* public int getCredits() return current credit balance
|
||||
* public ArrayList<MyDie> getDice() - return the
|
||||
* arraylist of the MyDie objects.
|
||||
*
|
||||
* public void roll() -- call the die object method to generate a new random
|
||||
* number for each die in the arraylist
|
||||
*
|
||||
* public int getTotal() -- return the total addition of the values in all
|
||||
* of the dice
|
||||
*
|
||||
* public void checkTriplets() -- Check if all three are same
|
||||
* +1 credit if true
|
||||
* public void checkDoubles() -- check for two of a kind
|
||||
*
|
||||
* public void checkLarge() -- Check if the sum of all dice is 10 or more
|
||||
* +1 credit if true
|
||||
*
|
||||
* public void updateCredits() - Calls on all bets and removes one credit
|
||||
* per play. Only allowed if enough credits.
|
||||
*
|
||||
* public boolean enoughCredits() -- return true if player has enough
|
||||
* credits to play this rounte;else false
|
||||
*
|
||||
* public void testRoll(int [] values) --
|
||||
* This method will roll the dice until the desired values entered
|
||||
* as the array of 3 int values have been rolled. This makes the
|
||||
* testing a lot easier because you can control what numbers are
|
||||
* rolled
|
||||
* If there are enough credits to play, this method has to do the
|
||||
* following:
|
||||
* Repeatedly roll each die in the array of dice until the desired
|
||||
* value is obtained.
|
||||
*
|
||||
* For example, if the method is called like this:
|
||||
* game.testRoll(new int [] {6,3,3});
|
||||
*
|
||||
* The arrayList should have those value in each die in that order.
|
||||
*******************GameManager**************************
|
||||
* GameManager Class
|
||||
* The GameManager will have to control and access the container class,
|
||||
* DiceCup.java
|
||||
*
|
||||
* GameManager should have only one variable. It'll be an instance of
|
||||
* DiceCup.
|
||||
* Constructors
|
||||
* Public GameManager ( int num ) -
|
||||
* instantiate a DiceCup object
|
||||
* The number determines SixDie or EightDie
|
||||
*
|
||||
* Accessor Methods
|
||||
* public String toString() - return the representation of the Game
|
||||
* public DiceCup getDice() - return the DiceCup Objects
|
||||
*
|
||||
* Main Method
|
||||
* Create an instance of GameManager
|
||||
* Take input from user to see if you want six or eight
|
||||
* Take input in loop to roll or stop
|
||||
*
|
||||
* Provide a print statement with Credits before bet, total sum of dice
|
||||
* and credits after bet
|
||||
*/
|
||||
|
95
Project/notes/temp-notes.java
Normal file
95
Project/notes/temp-notes.java
Normal file
@ -0,0 +1,95 @@
|
||||
/* Make a dice game */
|
||||
/*
|
||||
* played with three d6 or d8
|
||||
* bets placed on combinations that can apear on dice
|
||||
*
|
||||
* game begins with 10 credits
|
||||
* rolls cost one credit
|
||||
*
|
||||
* Bets are placed on possible outcomes
|
||||
* Payout increases number of credits by one if that outcome appears
|
||||
*
|
||||
* Large -- total value over 10
|
||||
* Three of a kind -- face value of all dice identical
|
||||
* Two of a kind -- face value of two are identical
|
||||
* So... I guess you need to get at least two in order to gain credits
|
||||
*
|
||||
* sixDie.java is premade and complete. Don't make changes.
|
||||
* *****************DiceCup******************************
|
||||
* create class DiceCup
|
||||
*
|
||||
* Create appropriate private vars for the Following
|
||||
*
|
||||
* an ArrayList of three MyDie objects
|
||||
* credit balance int
|
||||
*
|
||||
* Constructors
|
||||
* public DiceCup ()
|
||||
* instantiate and populate the arraylist
|
||||
* instantiate arraylist of three SixDie or EightDie objects
|
||||
* use loop to assign them to the elements of the arraylist
|
||||
* Initialize credit to 10
|
||||
*
|
||||
* Accessor Methods
|
||||
* public int getCredits() return current credit balance
|
||||
* public ArrayList<MyDie> getDice() - return the
|
||||
* arraylist of the MyDie objects.
|
||||
*
|
||||
* public void roll() -- call the die object method to generate a new random
|
||||
* number for each die in the arraylist
|
||||
*
|
||||
* public int getTotal() -- return the total addition of the values in all
|
||||
* of the dice
|
||||
*
|
||||
* public void checkTriplets() -- Check if all three are same
|
||||
* +1 credit if true
|
||||
* public void checkDoubles() -- check for two of a kind
|
||||
*
|
||||
* public void checkLarge() -- Check if the sum of all dice is 10 or more
|
||||
* +1 credit if true
|
||||
*
|
||||
* public void updateCredits() - Calls on all bets and removes one credit
|
||||
* per play. Only allowed if enough credits.
|
||||
*
|
||||
* public boolean enoughCredits() -- return true if player has enough
|
||||
* credits to play this rounte;else false
|
||||
*
|
||||
* public void testRoll(int [] values) --
|
||||
* This method will roll the dice until the desired values entered
|
||||
* as the array of 3 int values have been rolled. This makes the
|
||||
* testing a lot easier because you can control what numbers are
|
||||
* rolled
|
||||
* If there are enough credits to play, this method has to do the
|
||||
* following:
|
||||
* Repeatedly roll each die in the array of dice until the desired
|
||||
* value is obtained.
|
||||
*
|
||||
* For example, if the method is called like this:
|
||||
* game.testRoll(new int [] {6,3,3});
|
||||
*
|
||||
* The arrayList should have those value in each die in that order.
|
||||
*******************GameManager**************************
|
||||
* GameManager Class
|
||||
* The GameManager will have to control and access the container class,
|
||||
* DiceCup.java
|
||||
*
|
||||
* GameManager should have only one variable. It'll be an instance of
|
||||
* DiceCup.
|
||||
* Constructors
|
||||
* Public GameManager ( int num ) -
|
||||
* instantiate a DiceCup object
|
||||
* The number determines SixDie or EightDie
|
||||
*
|
||||
* Accessor Methods
|
||||
* public String toString() - return the representation of the Game
|
||||
* public DiceCup getDice() - return the DiceCup Objects
|
||||
*
|
||||
* Main Method
|
||||
* Create an instance of GameManager
|
||||
* Take input from user to see if you want six or eight
|
||||
* Take input in loop to roll or stop
|
||||
*
|
||||
* Provide a print statement with Credits before bet, total sum of dice
|
||||
* and credits after bet
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user