Browse Source

version 1.0

William Brown 6 years ago
parent
commit
d8c739ff8d
45 changed files with 2511 additions and 1 deletions
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. BIN
      src/main/.DS_Store
  4. BIN
      src/main/java/.DS_Store
  5. BIN
      src/main/java/io/.DS_Store
  6. BIN
      src/main/java/io/zipcoder/.DS_Store
  7. 156
    0
      src/main/java/io/zipcoder/casino/BlackJack.java
  8. 79
    0
      src/main/java/io/zipcoder/casino/BlackJackPlayer.java
  9. 29
    0
      src/main/java/io/zipcoder/casino/Card.java
  10. 16
    0
      src/main/java/io/zipcoder/casino/CardGame.java
  11. 93
    1
      src/main/java/io/zipcoder/casino/Casino.java
  12. 41
    0
      src/main/java/io/zipcoder/casino/Console.java
  13. 220
    0
      src/main/java/io/zipcoder/casino/Craps.java
  14. 19
    0
      src/main/java/io/zipcoder/casino/CrapsPlayer.java
  15. 56
    0
      src/main/java/io/zipcoder/casino/Dealer.java
  16. 49
    0
      src/main/java/io/zipcoder/casino/Deck.java
  17. 18
    0
      src/main/java/io/zipcoder/casino/Dice.java
  18. 15
    0
      src/main/java/io/zipcoder/casino/DiceGame.java
  19. 4
    0
      src/main/java/io/zipcoder/casino/Gamble.java
  20. 6
    0
      src/main/java/io/zipcoder/casino/Gambler.java
  21. 8
    0
      src/main/java/io/zipcoder/casino/Game.java
  22. 197
    0
      src/main/java/io/zipcoder/casino/GoFish.java
  23. 18
    0
      src/main/java/io/zipcoder/casino/GoFishPlayer.java
  24. 108
    0
      src/main/java/io/zipcoder/casino/Hand.java
  25. 7
    0
      src/main/java/io/zipcoder/casino/Opponent.java
  26. 31
    0
      src/main/java/io/zipcoder/casino/Player.java
  27. 40
    0
      src/main/java/io/zipcoder/casino/Rank.java
  28. 10
    0
      src/main/java/io/zipcoder/casino/Roulette.java
  29. 18
    0
      src/main/java/io/zipcoder/casino/RoulettePlayer.java
  30. 8
    0
      src/main/java/io/zipcoder/casino/Suit.java
  31. 17
    0
      src/main/java/io/zipcoder/casino/SystemConsole.java
  32. 54
    0
      src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java
  33. 390
    0
      src/test/java/io/zipcoder/casino/BlackJackTest.java
  34. 48
    0
      src/test/java/io/zipcoder/casino/CardTest.java
  35. 7
    0
      src/test/java/io/zipcoder/casino/CasinoTest.java
  36. 15
    0
      src/test/java/io/zipcoder/casino/ConsoleTest.java
  37. 37
    0
      src/test/java/io/zipcoder/casino/CrapsPlayerTest.java
  38. 130
    0
      src/test/java/io/zipcoder/casino/CrapsTest.java
  39. 56
    0
      src/test/java/io/zipcoder/casino/DealerTest.java
  40. 75
    0
      src/test/java/io/zipcoder/casino/DeckTest.java
  41. 25
    0
      src/test/java/io/zipcoder/casino/GoFishPlayerTest.java
  42. 163
    0
      src/test/java/io/zipcoder/casino/GoFishTest.java
  43. 177
    0
      src/test/java/io/zipcoder/casino/HandTest.java
  44. 34
    0
      src/test/java/io/zipcoder/casino/PlayerTest.java
  45. 37
    0
      src/test/java/io/zipcoder/casino/RoulettePlayerTest.java

BIN
.DS_Store View File


BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File


BIN
src/main/java/io/.DS_Store View File


BIN
src/main/java/io/zipcoder/.DS_Store View File


+ 156
- 0
src/main/java/io/zipcoder/casino/BlackJack.java View File

@@ -0,0 +1,156 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.io.IOException;
4
+import java.io.InputStream;
5
+import java.io.OutputStream;
6
+import java.io.PrintStream;
7
+
8
+public class BlackJack extends CardGame {
9
+
10
+    protected Dealer dealer1 = new Dealer();
11
+    private BlackJackPlayer player1;
12
+    private Console console = new Console();
13
+
14
+    public BlackJack(Player player) {
15
+        this.player1 = new BlackJackPlayer(player);
16
+
17
+    }
18
+
19
+    public BlackJackPlayer getPlayer(){
20
+        return player1;
21
+    }
22
+
23
+    public void setPlayer(BlackJackPlayer player1) {
24
+        this.player1 = player1;
25
+    }
26
+
27
+
28
+
29
+    public void playRound() {
30
+        double wager = console.getDoubleInput(blackJackWelcome());
31
+        player1.setWagerAmount(wager);
32
+
33
+        dealer1.deal(2, player1);
34
+        console.print(playerTotalsOutput());
35
+
36
+        dealer1.deal(2, dealer1);
37
+
38
+        blackJackRound();
39
+
40
+        adjustFunds();
41
+
42
+        playerWinLoss();
43
+    }
44
+
45
+
46
+    public String blackJackWelcome(){
47
+        return "Welcome to BlackJack!  Please enter your bet: ";
48
+    }
49
+
50
+
51
+    public String playerTotalsOutput(){
52
+        return "Your cards are " + player1.getPlayerHand().toString().trim() + "\n"
53
+                +"Your current total is " + player1.getPlayerHand().getTotal();
54
+    }
55
+
56
+    public String dealerTotalOutput(){
57
+        return "The dealer's cards are " + dealer1.getHand().toString().trim() + "\n"
58
+                + "The dealer's total is " + dealer1.getHand().getTotal();
59
+    }
60
+
61
+    public String hitOrStand(){
62
+        return "Would you like to hit or stand?";
63
+    }
64
+
65
+
66
+
67
+    public void blackJackRound(){
68
+            if (dealerBlackJackorBust(dealer1.getHand())){
69
+            } else if (playerBlackJackorBust(dealer1.getHand()))  {
70
+            } else{
71
+                playerSubRound();
72
+                dealerSubRound();
73
+            }
74
+    }
75
+
76
+
77
+
78
+    public void playerSubRound() {
79
+        String userInput = console.getStringInput(hitOrStand());
80
+            while (userInput.equalsIgnoreCase("Hit")|| userInput.equalsIgnoreCase("hit")) {
81
+                if (playerBlackJackorBust(player1.getPlayerHand())) {
82
+                    break;
83
+                } else if (userInput.equalsIgnoreCase("Stand") || userInput.equalsIgnoreCase("stand")) {
84
+                    break;
85
+                } else if (userInput.equalsIgnoreCase("Hit") || userInput.equalsIgnoreCase("hit")) {
86
+                    dealer1.pluck(player1.getPlayerHand());
87
+                    console.print(playerTotalsOutput());
88
+                    if(player1.getPlayerHand().getTotal() < 21){
89
+                        userInput = console.getStringInput(hitOrStand());}
90
+                }
91
+            }
92
+        }
93
+
94
+    public boolean playerBlackJackorBust(Hand playerhand){
95
+        if (playerhand.getTotal() >= 21){
96
+            return true;
97
+        }else{
98
+            return false;
99
+        }
100
+    }
101
+
102
+    public boolean dealerBlackJackorBust(Hand dealerhand){
103
+        if (dealerhand.getTotal() == 21 || dealerhand.getTotal() > 21){
104
+            return true;
105
+        }else{
106
+            return false;
107
+        }
108
+
109
+    }
110
+
111
+
112
+    public void dealerSubRound(){
113
+        while (dealer1.getHand().getTotal() <= 16) {
114
+                dealer1.pluck(dealer1.getHand());
115
+                break;
116
+            }
117
+
118
+    }
119
+
120
+    public boolean getResult(){
121
+        int dealerTotal = dealer1.getHand().getTotal();
122
+        int playerTotal = player1.getPlayerHand().getTotal();
123
+        if (dealerTotal > playerTotal && dealerTotal <= 21){
124
+            return false;
125
+        }else if(playerTotal > 21){
126
+            return false;
127
+        }else{
128
+            return true;
129
+        }
130
+    }
131
+
132
+    public void playerWinLoss(){
133
+        if (getResult()) {
134
+            console.print(dealerTotalOutput());
135
+            console.print("YOU WON!");
136
+            console.print("Your new account balance is " + String.format("%.2f", player1.getMoney()));
137
+        }else {
138
+            console.print(dealerTotalOutput());
139
+            console.print("YOU LOST!");
140
+            console.print("Your new account balance is " + String.format("%.2f", player1.getMoney()));
141
+        }
142
+
143
+    }
144
+
145
+
146
+    public void adjustFunds() {
147
+        if (getResult() == true) {
148
+            player1.setMoney(player1.getMoney() + (player1.getWagerAmount() * 1.5));
149
+
150
+        } else {
151
+            player1.setMoney(player1.getMoney() - player1.getWagerAmount());
152
+        }
153
+
154
+    }
155
+
156
+}

+ 79
- 0
src/main/java/io/zipcoder/casino/BlackJackPlayer.java View File

@@ -0,0 +1,79 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+public class BlackJackPlayer implements Gambler {
5
+    private Player player;
6
+    private Hand playerHand = new Hand();
7
+    private double money;
8
+    private int age;
9
+    private String name;
10
+    private double wagerAmount;
11
+
12
+    public Player getPlayer() {
13
+        return player;
14
+    }
15
+
16
+    public void setPlayer(Player player) {
17
+        this.player = player;
18
+    }
19
+
20
+    public double getMoney() {
21
+        return money;
22
+    }
23
+
24
+    public void setMoney(double money) {
25
+        this.money = money;
26
+    }
27
+
28
+    public int getAge() {
29
+        return age;
30
+    }
31
+
32
+    public void setAge(int age) {
33
+        this.age = age;
34
+    }
35
+
36
+    public String getName() {
37
+        return name;
38
+    }
39
+
40
+    public void setWagerAmount(double wagerAmount){
41
+        this.wagerAmount = wagerAmount;
42
+    }
43
+
44
+    public double getWagerAmount(){
45
+        return wagerAmount;
46
+    }
47
+
48
+
49
+
50
+    public void setName(String name) {
51
+        this.name = name;
52
+    }
53
+
54
+    public BlackJackPlayer(Player player) {
55
+
56
+        this.name = player.getName();
57
+        this.money = player.getMoney();
58
+        this.age = player.getAge();
59
+        this.player = player;
60
+    }
61
+
62
+    public void gamble(double wagerAmount) {
63
+        if (player.getMoney() < wagerAmount) {
64
+            System.out.println("You don't have enough money to cover that bet");
65
+        } else {
66
+            wagerAmount = wagerAmount * -1;
67
+            player.setMoney(player.getMoney() - wagerAmount);
68
+        }
69
+    }
70
+
71
+    public void setPlayerHand(Hand playerHand) {
72
+        this.playerHand = playerHand;
73
+    }
74
+
75
+    public Hand getPlayerHand() {
76
+        return playerHand;
77
+    }
78
+}
79
+

+ 29
- 0
src/main/java/io/zipcoder/casino/Card.java View File

@@ -0,0 +1,29 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Card implements Comparable<Card>{
4
+
5
+
6
+    private final Rank rank;
7
+    private final Suit suit;
8
+
9
+    Card(Rank rank, Suit suit) {
10
+        this.rank = rank;
11
+        this.suit = suit;
12
+    }
13
+
14
+    public int compareTo(Card o) {
15
+        if(o.getRank().getGoFishValue() > this.getRank().getGoFishValue()) {
16
+            return -1;
17
+        }else
18
+            return 1;
19
+        }
20
+
21
+
22
+    public Rank getRank() {
23
+        return rank;
24
+    }
25
+
26
+    public Suit getSuit() {
27
+        return suit;
28
+    }
29
+}

+ 16
- 0
src/main/java/io/zipcoder/casino/CardGame.java View File

@@ -0,0 +1,16 @@
1
+package io.zipcoder.casino;
2
+
3
+public class CardGame implements Game {
4
+    private Deck deck = new Deck();
5
+    private Dealer dealer;
6
+
7
+    public void playRound(){}
8
+
9
+    public boolean gameOver(){ return false;}
10
+
11
+    public boolean playing() {
12
+        return false;
13
+    }
14
+
15
+
16
+}

+ 93
- 1
src/main/java/io/zipcoder/casino/Casino.java View File

@@ -1,5 +1,97 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import java.io.InputStream;
5
+import java.io.PrintStream;
6
+import java.util.Scanner;
7
+
4 8
 public class Casino {
5
-}
9
+    private Player player;
10
+    private int response;
11
+//    private InputStream in;
12
+//    private PrintStream outprint;
13
+    private Game game;
14
+    private Console console = new Console();
15
+
16
+    public static void main(String[] args) {
17
+        Casino casino = new Casino();
18
+        casino.createPlayer();
19
+        casino.playGame();
20
+    }
21
+
22
+    public Casino() {
23
+//        this.player = player;
24
+    }
25
+
26
+    public String findName(){
27
+        return console.getStringInput("Please enter your name.");
28
+    }
29
+
30
+    public int findAge(){
31
+        return console.getIntegerInput("Please enter your age.");
32
+    }
33
+
34
+    public double findMoney(){
35
+        return console.getDoubleInput("Please enter the amount of money in your account");
36
+    }
37
+
38
+    public void createPlayer(){
39
+        player = new Player(findName(), findAge(), findMoney());
40
+    }
41
+
42
+    public void playGame() {
43
+        selectGamePrompt();
44
+        response = selectedGame();
45
+        while (response == 1 || response == 2 || response == 3) {
46
+            startGame();
47
+            selectGame();
48
+//            response = selectedGame();
49
+        }
50
+        console.print("Thank you for visiting ZipCasino");
51
+    }
52
+
53
+    public void selectGame() {
54
+        console.print("Welcome " + player.getName() + " to ZipCasino");
55
+        selectGamePrompt();
56
+        selectedGame();
57
+    }
58
+
59
+    public int selectedGame(){
60
+        int output = console.getIntegerInput("Enter the number for what game you want to play.");
61
+        return output;
62
+    }
63
+
64
+    public void startGame(){
65
+        startCraps();
66
+        startBlackJack();
67
+        startGoFish();
68
+    }
69
+
70
+    public void startCraps(){
71
+        if (response == 1) {
72
+            game = new Craps(player);
73
+            game.playRound();
74
+        }
75
+    }
76
+
77
+    public void startBlackJack(){
78
+        if (response == 2) {
79
+            game = new BlackJack(player);
80
+            game.playRound();
81
+        }
82
+    }
83
+
84
+    public void startGoFish(){
85
+        if (response == 3) {
86
+            game = new GoFish(player);
87
+            game.playRound();
88
+        }
89
+    }
90
+
91
+    public void selectGamePrompt(){
92
+        console.print("1: Craps");
93
+        console.print("2: BlackJack");
94
+        console.print("3: Go Fish. WIP");
95
+        console.print("Press any other key to leave.");
96
+    }
97
+}

+ 41
- 0
src/main/java/io/zipcoder/casino/Console.java View File

@@ -0,0 +1,41 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.io.InputStream;
4
+import java.io.PrintStream;
5
+import java.util.Scanner;
6
+
7
+public class Console {
8
+
9
+    private Scanner scanner = new Scanner(System.in);
10
+
11
+
12
+//    public Console(String input) {
13
+//        this.scanner = new Scanner(input);
14
+//    }
15
+
16
+public void print(String str){
17
+    System.out.println(str);
18
+}
19
+
20
+
21
+
22
+
23
+
24
+//    public  void print(String str, Object... args) {
25
+//        output.println(String.format(str, args));
26
+//    }
27
+//
28
+    public  String getStringInput(String prompt) {
29
+        print(prompt);
30
+        String input = scanner.nextLine();
31
+        return input;
32
+    }
33
+
34
+    public  Double getDoubleInput(String prompt) {
35
+        return Double.parseDouble(getStringInput(prompt));
36
+    }
37
+
38
+    public Integer getIntegerInput(String prompt) {
39
+        return getDoubleInput(prompt).intValue();
40
+    }
41
+}

+ 220
- 0
src/main/java/io/zipcoder/casino/Craps.java View File

@@ -0,0 +1,220 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.io.InputStream;
4
+import java.io.OutputStream;
5
+import java.io.PrintStream;
6
+import java.util.Scanner;
7
+
8
+public class Craps extends DiceGame {
9
+
10
+    private  double balance = 0;
11
+    private  double wager = 0;
12
+    private  CrapsPlayer player;
13
+    private int roll = throwDice();
14
+    private int point = throwDice();
15
+    private Console console = new Console();
16
+
17
+    public void setBalance(double balance) {
18
+        this.balance = balance;
19
+    }
20
+
21
+    public double getWager() {
22
+        return wager;
23
+    }
24
+
25
+    public CrapsPlayer getPlayer() {
26
+        return player;
27
+    }
28
+
29
+    public void setPlayer(CrapsPlayer player) {
30
+        this.player = player;
31
+    }
32
+
33
+    public int getRoll() {
34
+        return roll;
35
+    }
36
+
37
+    public void setRoll(int roll) {
38
+        this.roll = roll;
39
+    }
40
+
41
+    public void setPointTester(int point) {
42
+        this.point = point;
43
+    }
44
+
45
+    public Craps(Player player) {
46
+        this.player = new CrapsPlayer(player);
47
+       // player.getMoney(accountBalance());
48
+    }
49
+
50
+    public void instantWin(){
51
+        console.print("AYYYYY! YOU ROLLED A " + point + "!! GOOD JOB");
52
+        this.addWinnings();
53
+        console.print("Your new balance is "  + balance);
54
+    }
55
+
56
+    public void instantLose(){
57
+        console.print("Daaaamn homie, You rolled a " + point +" & crapped out! It's not looking to good for ya!");
58
+        this.subtractWinnings();
59
+        console.print("Your new balance is "  + balance);
60
+    }
61
+
62
+    public int setPoint(){
63
+        int point = rollDice();
64
+       console.print("Your point is now " + point + "..... You got this!");
65
+        return point;
66
+    }
67
+
68
+    public int chasePoint(){
69
+        console.print("You rolled a " + roll );
70
+        return roll;
71
+    }
72
+
73
+
74
+
75
+
76
+
77
+    public int throwDice(){
78
+       Dice dice = new Dice(2);
79
+       return dice.tossAndSum();
80
+    }
81
+
82
+
83
+    public void accountBalance(){
84
+
85
+       balance = console.getDoubleInput("How much money are you bringing to the table today?");
86
+    }
87
+
88
+
89
+    public  void addWinnings(){
90
+        balance = balance + wager;
91
+
92
+    }
93
+
94
+    public  void betAmount(){
95
+
96
+        wager = console.getDoubleInput("How much would you like to wager?");
97
+
98
+
99
+
100
+
101
+    }
102
+
103
+    public void lookForMatchPoint(int currentRoll){
104
+        int roll = 0;
105
+
106
+        console.print("Your point is " + point);
107
+        while (roll != 7) {
108
+            roll = throwDice();
109
+           console.print("You rolled a " + roll);
110
+            if (point == roll) {
111
+                this.winningRoll();
112
+                break;
113
+            }
114
+         else if(roll == 7) {
115
+                this.losingRoll();
116
+            }
117
+        }
118
+    }
119
+
120
+    public  void subtractWinnings(){
121
+        balance = balance - wager;
122
+
123
+    }
124
+
125
+    public  int rollDice(){
126
+        int roll = throwDice();
127
+
128
+        return roll;
129
+    }
130
+
131
+    public  void winningRoll(){
132
+        console.print("OK K K! WE HAVE A WINNER! STACK YA PAPER");
133
+        this.addWinnings();
134
+        console.print("Your new balance is "  + balance);
135
+    }
136
+
137
+    public void losingRoll(){
138
+        console.print("SMH YOU LOST! YOU MIGHT WANT TO CHOOSE ANOTHER GAME PLAYA!");
139
+        this.subtractWinnings();
140
+        console.print("Your new balance is "  + balance);
141
+    }
142
+
143
+
144
+
145
+    public  void promptUser(){
146
+
147
+
148
+
149
+        String answer1;
150
+
151
+        System.out.println();
152
+
153
+        console.print("Welcome to Craps! \n\n" +
154
+                "The rules of the game are as follows: \n" +
155
+                "If your first roll is is 7 or 11 you instantly win! \n" +
156
+                "If your first roll is 2 or 3 or 12 you instantly lose! \n" +
157
+                "When the first roll is 4,5,6,8,9 or 10, that will become your \"point\"! \n" +
158
+                "You WIN by re-rolling the \"point\" before rolling a 7! \n" +
159
+                "If you roll a 7 before your \"point\" you LOSE!");
160
+
161
+
162
+        answer1 = console.getStringInput("Would you like to play?");
163
+
164
+        answer1.equalsIgnoreCase("Yes");
165
+
166
+
167
+
168
+
169
+        console.print("\nGOOD LUCK... Your gonna need it! \n");
170
+
171
+
172
+
173
+    }
174
+
175
+    public  void setWager(double wager) {
176
+     this.wager = wager;
177
+    }
178
+
179
+    public  double getBalance() {
180
+        return balance;
181
+    }
182
+
183
+    public  int getPoint() {
184
+        return point;
185
+    }
186
+
187
+    public void playRound(){
188
+
189
+        promptUser();
190
+        accountBalance();
191
+        betAmount();
192
+
193
+        Scanner scanner = new Scanner(System.in);
194
+        String continuePlayAnswer;
195
+
196
+        do {
197
+            //calls the throw dice method to create 2 dice and give the sum of the 2.
198
+
199
+            //checks to see if the player instantly wins or loses
200
+            point = throwDice();
201
+
202
+            if ( point== 7 || point == 11) {
203
+                this.instantWin();
204
+            } else if (point == 2 || point == 3 || point == 12) {
205
+                this.instantLose();
206
+            //sets point and checks to see if the player rolls the point
207
+            } else lookForMatchPoint(point);
208
+
209
+
210
+            if(balance == 0) {
211
+                System.out.println("Sadly, you've lost all your money I think it's time for you to go home for the evening BUDDY! :(");
212
+                break;
213
+            }
214
+            System.out.println("Would you like to roll again?");
215
+            continuePlayAnswer = scanner.nextLine();
216
+        }while (continuePlayAnswer.trim().equalsIgnoreCase("yes"));
217
+
218
+    }
219
+}
220
+

+ 19
- 0
src/main/java/io/zipcoder/casino/CrapsPlayer.java View File

@@ -0,0 +1,19 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+public class CrapsPlayer implements Gambler {
5
+    private Player player;
6
+
7
+    public CrapsPlayer(Player player) {
8
+        this.player = player;
9
+    }
10
+
11
+    public void gamble(double wagerAmount) {
12
+        if (player.getMoney() < wagerAmount) {
13
+            System.out.println("You don't have enough money to cover that bet");
14
+        } else {
15
+            wagerAmount = wagerAmount * -1;
16
+            player.setMoney(wagerAmount);
17
+        }
18
+    }
19
+}

+ 56
- 0
src/main/java/io/zipcoder/casino/Dealer.java View File

@@ -0,0 +1,56 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Dealer {
4
+    private Hand dealerHand = new Hand();
5
+    Deck newDeck = new Deck();
6
+
7
+    public Hand getHand(){
8
+        return dealerHand;
9
+    }
10
+
11
+    public void setHand(Hand hand){
12
+        this.dealerHand = hand;
13
+    }
14
+
15
+    public void pluck(Hand playerHand) {
16
+        Card newCard = newDeck.pop();
17
+        playerHand.add(newCard);
18
+    }
19
+
20
+    public Deck getNewDeck() {
21
+        return newDeck;
22
+    }
23
+
24
+    public void deal(int numberOfCards, BlackJackPlayer player1){
25
+        newDeck.shuffleCards();
26
+        for (int i = 1; i <= numberOfCards; i++){
27
+            Card newCard = newDeck.pop();
28
+            Hand player1Hand = player1.getPlayerHand();
29
+            player1Hand.add(newCard);
30
+        }
31
+
32
+    }
33
+
34
+    public void deal(int numberOfCards, GoFishPlayer player2){
35
+        newDeck.shuffleCards();
36
+        for (int i = 1; i <= numberOfCards; i++){
37
+            Card newCard = newDeck.pop();
38
+            Hand player2Hand = player2.getPlayerHand();
39
+            player2Hand.add(newCard);
40
+        }
41
+
42
+    }
43
+
44
+    public void deal(int numberOfCards, Dealer dealer){
45
+        newDeck.shuffleCards();
46
+        for (int i = 1; i <= numberOfCards; i++){
47
+            Card newCard = newDeck.pop();
48
+            Hand dealerHand = dealer.getHand();
49
+            dealerHand.add(newCard);
50
+        }
51
+
52
+
53
+
54
+    }
55
+
56
+}

+ 49
- 0
src/main/java/io/zipcoder/casino/Deck.java View File

@@ -0,0 +1,49 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.Collections;
4
+import java.util.Stack;
5
+
6
+
7
+    public class Deck {
8
+
9
+
10
+        private Stack<Card> cards = new Stack<Card>();
11
+
12
+        public Deck() {
13
+            setCards();
14
+        }
15
+
16
+        public int getDeckSize(){
17
+            return cards.size();
18
+        }
19
+
20
+        public Stack<Card> getCards() {
21
+            return cards;
22
+        }
23
+
24
+        public void setCards() {
25
+            for (Suit suit : Suit.values()) {
26
+                for (Rank rank : Rank.values()) {
27
+                    cards.push(new Card(rank, suit));
28
+                }
29
+            }
30
+        }
31
+
32
+            public void shuffleCards () {
33
+                Collections.shuffle(cards);
34
+            }
35
+
36
+            public Card pop () {
37
+                return cards.pop();
38
+            }
39
+
40
+            public Card peek () {
41
+                return cards.peek();
42
+            }
43
+
44
+            public boolean isEmpty () {
45
+                return cards.empty();
46
+            }
47
+
48
+
49
+    }

+ 18
- 0
src/main/java/io/zipcoder/casino/Dice.java View File

@@ -0,0 +1,18 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Dice {
4
+    private int diceRolled = 0;
5
+
6
+    public Dice(int numOfDice){
7
+        diceRolled = numOfDice;
8
+    }
9
+
10
+    public int tossAndSum(){
11
+        int toss = 0;
12
+        for (int i = 0; i < diceRolled; i++) {
13
+            toss += (int) (Math.ceil(Math.random() * 6));
14
+        }
15
+        return toss;
16
+    }
17
+
18
+}

+ 15
- 0
src/main/java/io/zipcoder/casino/DiceGame.java View File

@@ -0,0 +1,15 @@
1
+package io.zipcoder.casino;
2
+
3
+public class DiceGame implements Game {
4
+    private Dice dice;
5
+
6
+    public boolean playing() {
7
+        return false;
8
+    }
9
+
10
+    public void playRound() {}
11
+
12
+    public boolean gameOver() {
13
+        return false;
14
+    }
15
+}

+ 4
- 0
src/main/java/io/zipcoder/casino/Gamble.java View File

@@ -0,0 +1,4 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Gamble {
4
+}

+ 6
- 0
src/main/java/io/zipcoder/casino/Gambler.java View File

@@ -0,0 +1,6 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Gambler {
4
+    void gamble(double wagerAmount);
5
+
6
+}

+ 8
- 0
src/main/java/io/zipcoder/casino/Game.java View File

@@ -0,0 +1,8 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Game {
4
+
5
+    boolean gameOver();
6
+
7
+    void playRound();
8
+}

+ 197
- 0
src/main/java/io/zipcoder/casino/GoFish.java View File

@@ -0,0 +1,197 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.ArrayList;
4
+import java.util.Scanner;
5
+
6
+public class GoFish extends CardGame {
7
+
8
+    private int playerScore;
9
+    private int aiScore;
10
+    private GoFishPlayer player;
11
+    private GoFishPlayer ai;
12
+
13
+    public static void main(String[] args) {
14
+        Player William = new Player("William", 18, 0.0);
15
+        GoFish goFish = new GoFish(William);
16
+
17
+        goFish.playRound();
18
+    }
19
+
20
+    public int getPlayerScore() {
21
+        return playerScore;
22
+    }
23
+
24
+    public void setPlayerScore(int playerScore) {
25
+        this.playerScore = playerScore;
26
+    }
27
+
28
+    public int getAiScore() {
29
+        return aiScore;
30
+    }
31
+
32
+    public void setAiScore(int aiScore) {
33
+        this.aiScore = aiScore;
34
+    }
35
+
36
+    public GoFish(Player player) {
37
+        Player ai = new Player("ai", 0, 0.0);
38
+
39
+        this.player = new GoFishPlayer(player);
40
+        this.ai = new GoFishPlayer(ai);
41
+    }
42
+
43
+    public Dealer dealer = new Dealer();
44
+
45
+    public boolean running(){
46
+        return true;
47
+    }
48
+
49
+    public void playRound() {
50
+        System.out.println("Welcome to Baby Fish.");
51
+        dealer.deal(7, player);
52
+        dealer.deal(7, ai);
53
+        while (dealer.getNewDeck().getDeckSize() != 0 && player.getPlayerHand().size() != 0 && ai.getPlayerHand().size() != 0) {
54
+            usersTurn();
55
+            aiTurn();
56
+        }
57
+        findWinner();
58
+    }
59
+
60
+    public void usersTurn(){
61
+        checkUserHandSize();
62
+        System.out.println(player.getPlayerHand().toString());
63
+        System.out.println("What are you asking for?");
64
+        Card userGuess = userGuess(tempInput());
65
+        playerGoFish(userGuess);
66
+        playerGotFish(userGuess);
67
+        checkUserHandSize();
68
+    }
69
+
70
+    public void aiTurn(){
71
+        checkAiHandSize();
72
+        Card aiGuess = aiGuess();
73
+        System.out.println("The AI asks for a " + aiGuess);
74
+        aiGoFish(aiGuess);
75
+        aiGotFish(aiGuess);
76
+        checkAiHandSize();
77
+    }
78
+
79
+    public void playerMatches(){
80
+        if(player.getPlayerHand().numberOfDuplicates() > 0) {
81
+            int num = player.getPlayerHand().numberOfDuplicates();
82
+            player.getPlayerHand().removeDuplicates();
83
+            playerScore = playerScore + num;
84
+        }
85
+    }
86
+
87
+    public void aiMatches(){
88
+        if(ai.getPlayerHand().numberOfDuplicates() > 0) {
89
+            int num = ai.getPlayerHand().numberOfDuplicates();
90
+            ai.getPlayerHand().removeDuplicates();
91
+            aiScore = aiScore + num;
92
+        }
93
+        //checks if hand is 0 & if deck is < 7
94
+    }
95
+
96
+    public Card userGuess(Card guess){
97
+        ArrayList<Card> playerHand = player.getPlayerHand().getHand();
98
+        if(playerHand.contains(guess)){
99
+            return guess;
100
+        }
101
+        return null;
102
+    }
103
+
104
+    public Card aiGuess(){
105
+        ArrayList<Card> aiHandHand= ai.getPlayerHand().getHand();
106
+        Card aiGuess = aiHandHand.get(0);
107
+        return aiGuess;
108
+    }
109
+
110
+    public void playerGoFish(Card guess){
111
+        if(!ai.getPlayerHand().contains(guess)){
112
+            System.out.println("The AI doesnt have a " + guess);
113
+            player.getPlayerHand().add(dealer.getNewDeck().pop());
114
+            playerMatches();
115
+            System.out.println("The player went fishing.");
116
+        }
117
+    }
118
+
119
+    public void playerGotFish(Card guess){
120
+        if(ai.getPlayerHand().contains(guess)){
121
+            ArrayList<Card> aiHandHand= ai.getPlayerHand().getHand();
122
+            aiHandHand.remove(guess);
123
+            aiMatches();
124
+            System.out.println("The player has gained a point.");
125
+        }
126
+    }
127
+
128
+    public void aiGoFish(Card guess){
129
+        if(!player.getPlayerHand().contains(guess)){
130
+            if(dealer.getNewDeck().getDeckSize() >= 1){
131
+                ai.getPlayerHand().add(dealer.getNewDeck().pop());
132
+            }
133
+            aiMatches();
134
+            System.out.println("The AI has gone fishing.");
135
+        }
136
+    }
137
+
138
+    public void aiGotFish(Card guess){
139
+        if(player.getPlayerHand().contains(guess)){
140
+            ArrayList<Card> playerHandHand= player.getPlayerHand().getHand();
141
+            playerHandHand.remove(guess);
142
+            aiMatches();
143
+            System.out.println("The AI has gained a point.");
144
+        }
145
+    }
146
+
147
+    public void checkUserHandSize(){
148
+        if(player.getPlayerHand().size() == 0 && dealer.getNewDeck().getDeckSize() > 7){
149
+            System.out.println("Your hand was empty here's some cards.");
150
+            dealer.deal(7, player);
151
+        } else if(player.getPlayerHand().size() == 0){
152
+            System.out.println("Your hand was empty here's some cards.");
153
+            dealer.deal(dealer.getNewDeck().getDeckSize(), player);
154
+        }
155
+    }
156
+
157
+    public void checkAiHandSize(){
158
+        if(ai.getPlayerHand().size() == 0 && dealer.getNewDeck().getDeckSize() > 7){
159
+            dealer.deal(7, ai);
160
+        } else if(ai.getPlayerHand().size() == 0){
161
+            dealer.deal(7, ai);
162
+        }
163
+    }
164
+
165
+    public boolean getResult(){
166
+        if(playerScore < aiScore){
167
+            System.out.println("AI won this time.");
168
+            return false;
169
+        }else {
170
+            System.out.println("You won!!!");
171
+            return true;
172
+        }
173
+    }
174
+
175
+    public void findWinner(){
176
+        if(playerScore < aiScore){
177
+            System.out.println("AI won this time.");
178
+//            return ai;
179
+        }else {
180
+            System.out.println("You won!!!");
181
+//            return player;
182
+        }
183
+    }
184
+
185
+    public Card tempInput(){
186
+        //TAKES A STRING INPUT CONVERTS IT TO RANK
187
+        Scanner scanner = new Scanner(System.in);
188
+        String input = scanner.nextLine().toLowerCase();
189
+        for(Card card : ai.getPlayerHand().getHand()){
190
+            if(input.equals(card.getRank().getStringValue())){
191
+                return card;
192
+            }
193
+        }
194
+        return null;
195
+    }
196
+
197
+}

+ 18
- 0
src/main/java/io/zipcoder/casino/GoFishPlayer.java View File

@@ -0,0 +1,18 @@
1
+package io.zipcoder.casino;
2
+
3
+public class GoFishPlayer {
4
+    private Player player;
5
+    private Hand playerHand = new Hand();
6
+
7
+    public GoFishPlayer(Player player) {
8
+        this.player = player;
9
+    }
10
+
11
+    public Hand getPlayerHand() {
12
+        return playerHand;
13
+    }
14
+
15
+    public void setPlayerHand(Hand playerHand) {
16
+        this.playerHand = playerHand;
17
+    }
18
+}

+ 108
- 0
src/main/java/io/zipcoder/casino/Hand.java View File

@@ -0,0 +1,108 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.ArrayList;
4
+import java.util.Collections;
5
+import java.util.LinkedHashSet;
6
+import java.util.Set;
7
+
8
+public class Hand {
9
+    private ArrayList<Card> playerHand = new ArrayList<Card>();
10
+
11
+    public Hand() {}
12
+
13
+    //public void add() {}
14
+
15
+    public void add(Card card){
16
+        playerHand.add(card);
17
+    }
18
+
19
+    public ArrayList<Card> getHand(){
20
+        return playerHand;
21
+    }
22
+
23
+    public int numberOfDuplicates(){
24
+
25
+
26
+        int countDuplicates = 0;
27
+        sortHand();
28
+        for (int i=1; i<playerHand.size(); i++) {
29
+            if(ifFirstCard(i))
30
+                {countDuplicates++;}
31
+            else if (twoInARow(i))
32
+                {countDuplicates++;}
33
+            else if (fourInARow(i))
34
+                {countDuplicates++;}
35
+        }
36
+            return countDuplicates;
37
+        }
38
+
39
+        public boolean ifFirstCard(int i){
40
+            if (i == 1 && playerHand.get(i - 1).getRank() == playerHand.get(i).getRank()) {
41
+
42
+                return true;
43
+            }
44
+            return false;
45
+        }
46
+
47
+        public boolean twoInARow(int i){
48
+        if (playerHand.get(i - 1).getRank() == playerHand.get(i).getRank()
49
+                    && playerHand.get(i - 2).getRank() != playerHand.get(i).getRank()) {
50
+        return true;}
51
+        return false;
52
+        }
53
+
54
+        public boolean fourInARow(int i){
55
+        if (i>3 && playerHand.get(i - 1).getRank() == playerHand.get(i).getRank()
56
+                && playerHand.get(i - 2).getRank() == playerHand.get(i).getRank()
57
+                && playerHand.get(i - 3).getRank() == playerHand.get(i).getRank()){
58
+            return true;
59
+        }
60
+    return false;}
61
+
62
+    public int size(){return playerHand.size();}
63
+
64
+    public boolean contains(Card card){ return playerHand.contains(card);}
65
+
66
+    public void sortHand(){
67
+        Collections.sort(playerHand);
68
+    }
69
+
70
+
71
+    //removes pairs of duplicates
72
+    public void removeDuplicates(){
73
+        sortHand();
74
+        for (int i=playerHand.size()-3; i>=0; i--) {
75
+            if (playerHand.get(i + 1).getRank() == playerHand.get(i).getRank()) {
76
+                playerHand.remove(i+1);
77
+                playerHand.remove(i);
78
+            }
79
+        }
80
+    }
81
+
82
+    //returns number of occurrences of input
83
+    public int getNumberOfRankOccurrences(Card card) {
84
+        int count =0;
85
+        for(int i = 0; i<playerHand.size(); i++){
86
+            if(playerHand.get(i).getRank() == card.getRank())
87
+            {count++;}
88
+        }
89
+        return count;
90
+    }
91
+
92
+    //Creates a string with rank and suit
93
+    public String toString() {
94
+        String  result = "";
95
+        for (Card card : playerHand){
96
+            result += card.getRank().toString() + card.getSuit().toString() + " ";
97
+        }
98
+        return result;
99
+    }
100
+
101
+    public int getTotal(){
102
+        int result = 0;
103
+        for(Card card : playerHand){
104
+            result += card.getRank().getBlackJackValue();
105
+        }
106
+        return result;
107
+    }
108
+}

+ 7
- 0
src/main/java/io/zipcoder/casino/Opponent.java View File

@@ -0,0 +1,7 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Opponent {
4
+    void pluck();
5
+
6
+
7
+}

+ 31
- 0
src/main/java/io/zipcoder/casino/Player.java View File

@@ -0,0 +1,31 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Player {
4
+
5
+    private String name;
6
+    private int age;
7
+    private double money = 0;
8
+
9
+
10
+    public Player(String name, int age, double money) {
11
+        this.name = name;
12
+        this.age = age;
13
+        this.money = money;
14
+    }
15
+
16
+    public String getName() {
17
+        return name;
18
+    }
19
+
20
+    public int getAge() {
21
+        return age;
22
+    }
23
+
24
+    public double getMoney() {
25
+        return money;
26
+    }
27
+
28
+    public void setMoney(double money) {
29
+        this.money += money;
30
+    }
31
+}

+ 40
- 0
src/main/java/io/zipcoder/casino/Rank.java View File

@@ -0,0 +1,40 @@
1
+package io.zipcoder.casino;
2
+
3
+public enum Rank {
4
+    ACE(1, "ace"),
5
+    TWO(2, "two"),
6
+    THREE(3, "three"),
7
+    FOUR(4, "four"),
8
+    FIVE(5, "five"),
9
+    SIX(6, "six"),
10
+    SEVEN(7, "seven"),
11
+    EIGHT(8, "eight"),
12
+    NINE(9, "nine"),
13
+    TEN(10, "ten"),
14
+    JACK(10, "jack"),
15
+    QUEEN(10, "queen"),
16
+    KING(10, "king");
17
+
18
+    private int goFishValue;
19
+    private int blackJackValue;
20
+    private String stringValue;
21
+
22
+    Rank(int goFishValue, String stringValue) {
23
+        this.goFishValue = goFishValue;
24
+        this.blackJackValue = goFishValue;
25
+        this.stringValue = stringValue;
26
+    }
27
+
28
+
29
+    public int getGoFishValue() {
30
+        return goFishValue;
31
+    }
32
+
33
+    public int getBlackJackValue() {
34
+        return blackJackValue;
35
+    }
36
+
37
+    public String getStringValue() {
38
+        return stringValue;
39
+    }
40
+}

+ 10
- 0
src/main/java/io/zipcoder/casino/Roulette.java View File

@@ -0,0 +1,10 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Roulette {
4
+
5
+    private RoulettePlayer player;
6
+
7
+    public Roulette(Player player) {
8
+        this.player = new RoulettePlayer(player);
9
+    }
10
+}

+ 18
- 0
src/main/java/io/zipcoder/casino/RoulettePlayer.java View File

@@ -0,0 +1,18 @@
1
+package io.zipcoder.casino;
2
+
3
+public class RoulettePlayer implements Gambler {
4
+    private Player player;
5
+
6
+    public RoulettePlayer(Player player) {
7
+        this.player = player;
8
+    }
9
+
10
+    public void gamble(double wagerAmount) {
11
+        if (player.getMoney() < wagerAmount) {
12
+            System.out.println("You don't have enough money to cover that bet");
13
+        } else {
14
+            wagerAmount = wagerAmount * -1;
15
+            player.setMoney(wagerAmount);
16
+        }
17
+    }
18
+}

+ 8
- 0
src/main/java/io/zipcoder/casino/Suit.java View File

@@ -0,0 +1,8 @@
1
+package io.zipcoder.casino;
2
+
3
+public enum Suit {
4
+    CLUBS,
5
+    DIAMONDS,
6
+    HEARTS,
7
+    SPADES
8
+}

+ 17
- 0
src/main/java/io/zipcoder/casino/SystemConsole.java View File

@@ -0,0 +1,17 @@
1
+//package io.zipcoder.casino;
2
+//
3
+//public class SystemConsole {
4
+//    private static final Console console = new Console(System.in, System.out);
5
+//
6
+//    private static void print(String str, Object... args) {
7
+//        console.print(str, args);
8
+//    }
9
+//
10
+//    public static String getStringInput(String str, Object... args) {
11
+//        return console.getStringInput(str, args);
12
+//    }
13
+//
14
+//    public static Double getDoubleInput(String str, Object... args) {
15
+//
16
+//    }
17
+//}

+ 54
- 0
src/test/java/io/zipcoder/casino/BlackJackPlayerTest.java View File

@@ -0,0 +1,54 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class BlackJackPlayerTest {
7
+
8
+    @Test
9
+    public void testGamble() {
10
+        // Given
11
+        Player player = new Player("Curtis", 36, 100);
12
+        BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
13
+        double expectedOutput = 100 - 75;
14
+
15
+        // When
16
+        blackJackPlayer.gamble(75);
17
+        double actualOutput = 25;
18
+
19
+        // Then
20
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
21
+    }
22
+
23
+    @Test
24
+    public void testGamble2() {
25
+        // Given
26
+        Player player = new Player("Curtis", 36, 100);
27
+        BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
28
+        double expectedOutput = 100;
29
+
30
+        // When
31
+        blackJackPlayer.gamble(200);
32
+        double actualOutput = 100;
33
+
34
+        // Then
35
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
36
+    }
37
+
38
+    @Test
39
+    public void testSetAndGetHand() {
40
+        // Given
41
+        Player player = new Player("Curtis", 36, 100);
42
+        BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
43
+        Hand hand = new Hand();
44
+        blackJackPlayer.setPlayerHand(hand);
45
+        Hand expectedOutput = hand;
46
+
47
+        // When
48
+        Hand actualOutput = blackJackPlayer.getPlayerHand();
49
+
50
+
51
+        // Then
52
+        Assert.assertEquals(expectedOutput, actualOutput);
53
+    }
54
+}

+ 390
- 0
src/test/java/io/zipcoder/casino/BlackJackTest.java View File

@@ -0,0 +1,390 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class BlackJackTest {
8
+
9
+    Player playerTest = new Player("Joe", 23, 100);
10
+    BlackJack blackjack1 = new BlackJack(playerTest);
11
+    BlackJackPlayer player = new BlackJackPlayer(playerTest);
12
+    Dealer dealer1 = new Dealer();
13
+
14
+    @Test
15
+    public void setGetBlackJackPlayerTest(){
16
+        BlackJackPlayer expectedOutput = player;
17
+
18
+        blackjack1.setPlayer(player);
19
+        BlackJackPlayer actualOutput = blackjack1.getPlayer();
20
+
21
+        Assert.assertEquals(expectedOutput, actualOutput);
22
+    }
23
+
24
+    @Test
25
+    public void blacjackWelcomeTest(){
26
+        String expectedOutput = "Welcome to BlackJack!  Please enter your bet: ";
27
+
28
+        String actualOutput = blackjack1.blackJackWelcome();
29
+
30
+        Assert.assertEquals(expectedOutput, actualOutput);
31
+    }
32
+
33
+    @Test
34
+    public void hitOrStandTest(){
35
+        String expectedOutput = "Would you like to hit or stand?";
36
+
37
+        String actualOutput = blackjack1.hitOrStand();
38
+
39
+        Assert.assertEquals(expectedOutput, actualOutput);
40
+    }
41
+
42
+    @Test
43
+    public void playerTotalsTest(){
44
+        Hand h12 = new Hand();
45
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
46
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
47
+        this.player.setPlayerHand(h12);
48
+        blackjack1.setPlayer(this.player);
49
+
50
+        String expectedOutput = "Your cards are QUEENCLUBS JACKDIAMONDS"+"\n"+ "Your current total is 20";
51
+
52
+        String actualOutput = blackjack1.playerTotalsOutput();
53
+
54
+        Assert.assertEquals(expectedOutput, actualOutput);
55
+    }
56
+
57
+    @Test
58
+    public void dealerTotalsTest(){
59
+        Hand h12 = new Hand();
60
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
61
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
62
+        this.dealer1.setHand(h12);
63
+        blackjack1.dealer1 = this.dealer1;
64
+
65
+        String expectedOutput = "The dealer's cards are QUEENCLUBS JACKDIAMONDS"+"\n"+ "The dealer's total is 20";
66
+
67
+        String actualOutput = blackjack1.dealerTotalOutput();
68
+
69
+        Assert.assertEquals(expectedOutput, actualOutput);
70
+    }
71
+
72
+
73
+
74
+    @Test
75
+    public void playerBlackJackorBustTest(){
76
+        Hand h = new Hand();
77
+        h.add(new Card(Rank.TWO, Suit.CLUBS));
78
+        h.add(new Card(Rank.JACK, Suit.DIAMONDS));
79
+        this.player.setPlayerHand(h);
80
+
81
+        boolean actualOutput = blackjack1.playerBlackJackorBust(h);
82
+
83
+        Assert.assertFalse(actualOutput);
84
+    }
85
+
86
+
87
+    @Test
88
+    public void playerBlackJackorBustTest2(){
89
+        Hand h1 = new Hand();
90
+        h1.add(new Card(Rank.TWO, Suit.CLUBS));
91
+        h1.add(new Card(Rank.JACK, Suit.DIAMONDS));
92
+        h1.add(new Card(Rank.QUEEN, Suit.SPADES));
93
+        this.player.setPlayerHand(h1);
94
+
95
+        boolean actualOutput = blackjack1.playerBlackJackorBust(h1);
96
+
97
+        Assert.assertTrue(actualOutput);
98
+    }
99
+
100
+    @Test
101
+    public void playerBlackJackorBustTest3(){
102
+        Hand h2 = new Hand();
103
+        h2.add(new Card(Rank.ACE, Suit.CLUBS));
104
+        h2.add(new Card(Rank.JACK, Suit.DIAMONDS));
105
+        h2.add(new Card(Rank.QUEEN, Suit.SPADES));
106
+        this.player.setPlayerHand(h2);
107
+
108
+        boolean actualOutput = blackjack1.playerBlackJackorBust(h2);
109
+
110
+        Assert.assertTrue(actualOutput);
111
+    }
112
+
113
+    @Test
114
+    public void dealerBlackJackorBust(){
115
+        Hand h3 = new Hand();
116
+        h3.add(new Card(Rank.ACE, Suit.CLUBS));
117
+        h3.add(new Card(Rank.JACK, Suit.DIAMONDS));
118
+        h3.add(new Card(Rank.QUEEN, Suit.SPADES));
119
+        this.dealer1.setHand(h3);
120
+
121
+        boolean actualOutput = blackjack1.dealerBlackJackorBust(h3);
122
+
123
+        Assert.assertTrue(actualOutput);
124
+
125
+    }
126
+
127
+    @Test
128
+    public void dealerBlackJackorBust1(){
129
+        Hand h4 = new Hand();
130
+        h4.add(new Card(Rank.TWO, Suit.CLUBS));
131
+        h4.add(new Card(Rank.JACK, Suit.DIAMONDS));
132
+        h4.add(new Card(Rank.QUEEN, Suit.SPADES));
133
+        this.dealer1.setHand(h4);
134
+
135
+        boolean actualOutput = blackjack1.dealerBlackJackorBust(h4);
136
+
137
+        Assert.assertTrue(actualOutput);
138
+
139
+    }
140
+
141
+    @Test
142
+    public void dealerBlackJackorBust2(){
143
+        Hand h5 = new Hand();
144
+        h5.add(new Card(Rank.TWO, Suit.CLUBS));
145
+        h5.add(new Card(Rank.JACK, Suit.DIAMONDS));
146
+        this.dealer1.setHand(h5);
147
+
148
+        boolean expectedOutput = false;
149
+
150
+        boolean actualOutput = blackjack1.dealerBlackJackorBust(h5);
151
+
152
+        Assert.assertFalse(actualOutput);
153
+
154
+    }
155
+
156
+//    @Test
157
+//    public void playerSubRoundTestOver21(){
158
+//        Hand h6 = new Hand();
159
+//        h6.add(new Card(Rank.TWO, Suit.CLUBS));
160
+//        h6.add(new Card(Rank.JACK, Suit.DIAMONDS));
161
+//        h6.add(new Card(Rank.QUEEN, Suit.SPADES));
162
+//        this.player.setPlayerHand(h6);
163
+//        blackjack1.dealer1 = this.dealer1;
164
+//
165
+//        int expectedOutput = 22;
166
+//
167
+//        blackjack1.playerSubRound();
168
+//        int actualOutput = player.getPlayerHand().getTotal();
169
+//
170
+//        Assert.assertEquals(expectedOutput, actualOutput);
171
+//
172
+//    }
173
+//
174
+//    @Test
175
+//    public void playerSubRoundTestHit(){
176
+//        Hand h6 = new Hand();
177
+//        h6.add(new Card(Rank.TWO, Suit.CLUBS));
178
+//        h6.add(new Card(Rank.QUEEN, Suit.SPADES));
179
+//        this.player.setPlayerHand(h6);
180
+//        blackjack1.dealer1 = this.dealer1;
181
+//        //blackjack1. = this.player1;
182
+//
183
+//
184
+//        blackjack1.playerSubRound();
185
+//        int actualOutput = player.getPlayerHand().getTotal();
186
+//
187
+//        Assert.assertTrue(actualOutput > 12);
188
+//
189
+//    }
190
+//
191
+//    @Test
192
+//    public void playerSubRoundTestStay(){
193
+//        Hand h7 = new Hand();
194
+//        h7.add(new Card(Rank.TWO, Suit.CLUBS));
195
+//        h7.add(new Card(Rank.JACK, Suit.DIAMONDS));
196
+//        this.player.setPlayerHand(h7);
197
+//        blackjack1.dealer1 = this.dealer1;
198
+//
199
+//
200
+//        int expectedOutput = 12;
201
+//
202
+//        blackjack1.playerSubRound();
203
+//        int actualOutput = player.getPlayerHand().getTotal();
204
+//
205
+//        Assert.assertEquals(expectedOutput, actualOutput);
206
+//
207
+//    }
208
+
209
+    @Test
210
+    public void dealerSubRoundTest(){
211
+        Hand h8 = new Hand();
212
+        h8.add(new Card(Rank.TWO, Suit.CLUBS));
213
+        h8.add(new Card(Rank.JACK, Suit.DIAMONDS));
214
+        this.dealer1.setHand(h8);
215
+        blackjack1.dealer1 = this.dealer1;
216
+
217
+
218
+        blackjack1.dealerSubRound();
219
+        int actualOutput = dealer1.getHand().getTotal();
220
+
221
+        Assert.assertTrue(actualOutput > 16);
222
+    }
223
+
224
+    @Test
225
+    public void dealerSubRoundTest2(){
226
+        Hand h9 = new Hand();
227
+        h9.add(new Card(Rank.TWO, Suit.CLUBS));
228
+        h9.add(new Card(Rank.JACK, Suit.DIAMONDS));
229
+        h9.add(new Card(Rank.QUEEN, Suit.SPADES));
230
+        this.dealer1.setHand(h9);
231
+        blackjack1.dealer1 = this.dealer1;
232
+
233
+        int expectedOutput = 22;
234
+
235
+
236
+        blackjack1.dealerSubRound();
237
+        int actualOutput = dealer1.getHand().getTotal();
238
+
239
+        Assert.assertEquals(expectedOutput, actualOutput);
240
+    }
241
+
242
+    @Test
243
+    public void dealerSubRoundTest3(){
244
+        Hand h10 = new Hand();
245
+        h10.add(new Card(Rank.SIX, Suit.CLUBS));
246
+        h10.add(new Card(Rank.JACK, Suit.DIAMONDS));
247
+        this.dealer1.setHand(h10);
248
+        blackjack1.dealer1 = this.dealer1;
249
+
250
+        blackjack1.dealerSubRound();
251
+        int actualOutput = dealer1.getHand().getTotal();
252
+
253
+        Assert.assertTrue(actualOutput > 16);
254
+    }
255
+
256
+    @Test
257
+    public void getResultTestDealerBlackJack(){
258
+        Hand h11 = new Hand();
259
+        h11.add(new Card(Rank.ACE, Suit.CLUBS));
260
+        h11.add(new Card(Rank.JACK, Suit.DIAMONDS));
261
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
262
+        this.dealer1.setHand(h11);
263
+        blackjack1.dealer1 = this.dealer1;
264
+
265
+        Hand h12 = new Hand();
266
+        h12.add(new Card(Rank.FIVE, Suit.CLUBS));
267
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
268
+        this.player.setPlayerHand(h12);
269
+
270
+
271
+        boolean actualOutput = blackjack1.getResult();
272
+
273
+        Assert.assertFalse(actualOutput);
274
+
275
+    }
276
+
277
+    @Test
278
+    public void getResultTestDealerWin(){
279
+        Hand h11 = new Hand();
280
+        h11.add(new Card(Rank.JACK, Suit.DIAMONDS));
281
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
282
+        this.dealer1.setHand(h11);
283
+        blackjack1.dealer1 = this.dealer1;
284
+
285
+        Hand h12 = new Hand();
286
+        h12.add(new Card(Rank.FIVE, Suit.CLUBS));
287
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
288
+        this.player.setPlayerHand(h12);
289
+
290
+        boolean actualOutput = blackjack1.getResult();
291
+
292
+        Assert.assertFalse(actualOutput);
293
+
294
+    }
295
+
296
+    @Test
297
+    public void getResultTestPlayerWin(){
298
+        Hand h11 = new Hand();
299
+        h11.add(new Card(Rank.FIVE, Suit.DIAMONDS));
300
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
301
+        this.dealer1.setHand(h11);
302
+        blackjack1.dealer1 = this.dealer1;
303
+
304
+        Hand h12 = new Hand();
305
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
306
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
307
+        this.player.setPlayerHand(h12);
308
+        blackjack1.setPlayer(this.player);
309
+
310
+
311
+        System.out.println(blackjack1.getResult());
312
+        boolean actualOutput = blackjack1.getResult();
313
+
314
+        Assert.assertTrue(actualOutput);
315
+
316
+    }
317
+
318
+    @Test
319
+    public void playerWinLossWinTest(){
320
+        Hand h11 = new Hand();
321
+        h11.add(new Card(Rank.FIVE, Suit.DIAMONDS));
322
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
323
+        this.dealer1.setHand(h11);
324
+        blackjack1.dealer1 = this.dealer1;
325
+
326
+        Hand h12 = new Hand();
327
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
328
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
329
+        this.player.setPlayerHand(h12);
330
+        blackjack1.setPlayer(this.player);
331
+
332
+        blackjack1.getResult();
333
+        String expectedOutput = "The dealer's cards are FIVEDIAMONDS QUEENDIAMONDS"+"\n"+ "The dealer's total is 15"+"\n"+
334
+                "YOU WON!"+"\n";
335
+
336
+    }
337
+
338
+    @Test
339
+    public void adjustFundsWin(){
340
+        player.setWagerAmount(25.00);
341
+
342
+        Hand h11 = new Hand();
343
+        h11.add(new Card(Rank.FIVE, Suit.DIAMONDS));
344
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
345
+        this.dealer1.setHand(h11);
346
+        blackjack1.dealer1 = this.dealer1;
347
+
348
+        Hand h12 = new Hand();
349
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
350
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
351
+        this.player.setPlayerHand(h12);
352
+        blackjack1.setPlayer(this.player);
353
+
354
+        double expectedOutput = 137.50;
355
+
356
+        blackjack1.adjustFunds();
357
+        double actualOutput = player.getMoney();
358
+
359
+        Assert.assertEquals(expectedOutput, actualOutput, .002);
360
+
361
+    }
362
+
363
+    @Test
364
+    public void adjustFundsLoss(){
365
+        player.setWagerAmount(25.00);
366
+
367
+        Hand h11 = new Hand();
368
+        h11.add(new Card(Rank.FIVE, Suit.DIAMONDS));
369
+        h11.add(new Card(Rank.QUEEN, Suit.DIAMONDS));
370
+        this.player.setPlayerHand(h11);
371
+        blackjack1.setPlayer(this.player);
372
+
373
+
374
+        Hand h12 = new Hand();
375
+        h12.add(new Card(Rank.QUEEN, Suit.CLUBS));
376
+        h12.add(new Card(Rank.JACK, Suit.DIAMONDS));
377
+        this.dealer1.setHand(h12);
378
+        blackjack1.dealer1 = this.dealer1;
379
+
380
+
381
+        double expectedOutput = 75.00;
382
+        blackjack1.adjustFunds();
383
+
384
+        double actualOutput = player.getMoney();
385
+
386
+        Assert.assertEquals(expectedOutput, actualOutput, .002);
387
+
388
+    }
389
+
390
+}

+ 48
- 0
src/test/java/io/zipcoder/casino/CardTest.java View File

@@ -0,0 +1,48 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import static org.junit.Assert.*;
9
+
10
+public class CardTest {
11
+
12
+    Card card;
13
+
14
+    @Before
15
+    public void setup(){
16
+
17
+        card = new Card(card.getRank(), card.getSuit());
18
+
19
+        card = new Card(Rank.ACE, Suit.CLUBS);
20
+    }
21
+
22
+    @Test
23
+    public void getRankTest() {
24
+        Rank expected =card.getRank();
25
+        Rank actual = Rank.ACE;
26
+        Assert.assertEquals(expected, actual);
27
+
28
+    }
29
+
30
+//    @Test
31
+//    public void getRankTest() {
32
+//
33
+//        Enum expected = card.getRank();
34
+//        Enum actual = Rank.ACE;
35
+//
36
+//        Rank expected =card.getRank();
37
+//        Rank actual = Rank.ACE;
38
+//
39
+//        Assert.assertEquals(expected, actual);
40
+//    }
41
+
42
+    @Test
43
+    public void getSuitTest() {
44
+        Suit expected =card.getSuit();
45
+        Suit actual = Suit.CLUBS;
46
+        Assert.assertEquals(expected, actual);
47
+    }
48
+}

+ 7
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java View File

@@ -1,5 +1,12 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import org.junit.Test;
5
+
4 6
 public class CasinoTest {
7
+    @Test
8
+    public void test(){
9
+        Casino casino = new Casino();
10
+        casino.selectGamePrompt();
11
+    }
5 12
 }

+ 15
- 0
src/test/java/io/zipcoder/casino/ConsoleTest.java View File

@@ -0,0 +1,15 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class ConsoleTest {
6
+
7
+//    @Test
8
+//    public void test() {
9
+//        Console c = new Console(System.in, System.out);
10
+//        c.print("Select one of the options [%s %s %s]",
11
+//                "first option",
12
+//                "second option",
13
+//                "third option");
14
+//    }
15
+}

+ 37
- 0
src/test/java/io/zipcoder/casino/CrapsPlayerTest.java View File

@@ -0,0 +1,37 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CrapsPlayerTest {
7
+
8
+    @Test
9
+    public void testGamble() {
10
+        // Given
11
+        Player player = new Player("Curtis", 36, 100);
12
+        CrapsPlayer crapsPlayer = new CrapsPlayer(player);
13
+        double expectedOutput = 100 - 50;
14
+
15
+        // When
16
+        crapsPlayer.gamble(50);
17
+        double actualOutput = 50;
18
+
19
+        // Then
20
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
21
+    }
22
+
23
+    @Test
24
+    public void testGamble2() {
25
+        // Given
26
+        Player player = new Player("Curtis", 36, 100);
27
+        CrapsPlayer crapsPlayer = new CrapsPlayer(player);
28
+        double expectedOutput = 100;
29
+
30
+        // When
31
+        crapsPlayer.gamble(200);
32
+        double actualOutput = 100;
33
+
34
+        // Then
35
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
36
+    }
37
+}

+ 130
- 0
src/test/java/io/zipcoder/casino/CrapsTest.java View File

@@ -0,0 +1,130 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import static org.junit.Assert.*;
8
+
9
+public class CrapsTest {
10
+
11
+    Craps craps;
12
+    Player player = new Player("Maggie", 27, 10000);
13
+    Console console = new Console();
14
+
15
+    @Before
16
+    public void setup(){
17
+       craps = new Craps(player);
18
+    }
19
+
20
+    @Test
21
+    public void instantWinTest() {
22
+        craps.setWager(20);
23
+        craps.instantWin();
24
+        double expected = 20;
25
+        double actual = craps.getBalance();
26
+        Assert.assertEquals(expected, actual, .1);
27
+    }
28
+
29
+    @Test
30
+    public void instantLoseTest() {
31
+        craps.setWager(100);
32
+        craps.instantLose();
33
+        double expected = -100;
34
+        double actual = craps.getBalance();
35
+        Assert.assertEquals(expected,actual, .1);
36
+    }
37
+
38
+    @Test
39
+    public void setPoint() {
40
+        craps.setPointTester(5);
41
+        craps.setPoint();
42
+        int expected = 5;
43
+        int actual = craps.getPoint();
44
+        Assert.assertEquals(expected,actual);
45
+    }
46
+
47
+    @Test
48
+    public void chasePoint() {
49
+        craps.setRoll(5);
50
+
51
+        int expected = 5;
52
+        int actual = craps.chasePoint();
53
+        Assert.assertEquals(expected,actual);
54
+
55
+    }
56
+
57
+    @Test
58
+    public void throwDice() {
59
+        craps.throwDice();
60
+        boolean correct = false;
61
+
62
+        int expected = craps.throwDice();
63
+        int actual = craps.throwDice();
64
+        if(actual >= 2 && actual <= 12){
65
+            correct = true;
66
+        }
67
+
68
+        Assert.assertTrue(correct);
69
+    }
70
+
71
+
72
+    @Test
73
+    public void accountBalanceTest() {
74
+
75
+        craps.setBalance(1000);
76
+        double expected = 1000;
77
+        double actual = craps.getBalance();
78
+
79
+        Assert.assertEquals(expected,actual, .01);
80
+    }
81
+
82
+    @Test
83
+    public void addWinnings() {
84
+        craps.setBalance(40);
85
+        craps.setWager(10);
86
+        craps.addWinnings();
87
+        double expected = craps.getBalance();
88
+        double actual =50;
89
+        Assert.assertEquals(expected, actual, .1);
90
+
91
+    }
92
+
93
+
94
+    @Test
95
+    public void lookForMatchPoint() {
96
+        craps.setPointTester(5);
97
+        craps.setPoint();
98
+
99
+        craps.setRoll(5);
100
+
101
+        boolean correct = false;
102
+
103
+        
104
+    }
105
+
106
+    @Test
107
+    public void subtractWinnings() {
108
+    }
109
+
110
+    @Test
111
+    public void rollDice() {
112
+
113
+
114
+    }
115
+
116
+    @Test
117
+    public void winningRoll() {
118
+    }
119
+
120
+    @Test
121
+    public void losingRoll() {
122
+    }
123
+
124
+
125
+
126
+
127
+    @Test
128
+    public void playRound() {
129
+    }
130
+}

+ 56
- 0
src/test/java/io/zipcoder/casino/DealerTest.java View File

@@ -0,0 +1,56 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+import org.junit.Assert;
5
+
6
+public class DealerTest {
7
+    Dealer dealer1 = new Dealer();
8
+    Player player = new Player("Joe", 21, 100);
9
+    BlackJackPlayer player1 = new BlackJackPlayer(player);
10
+    GoFishPlayer player2 = new GoFishPlayer(player);
11
+
12
+
13
+    @Test
14
+    public void dealTest(){
15
+//        int expectedOutput = 0;
16
+//        int actualOutput = dealer1.getHand().size();
17
+
18
+        dealer1.deal(2, dealer1);
19
+
20
+        int expectedOutput = 2;
21
+        int actualOutput = dealer1.getHand().size();
22
+
23
+        Assert.assertEquals(expectedOutput, actualOutput);
24
+    }
25
+
26
+    @Test
27
+    public void dealBlackJackTest(){
28
+        int expectedOutput = 2;
29
+
30
+        dealer1.deal(2, player1);
31
+        int actualOutput = player1.getPlayerHand().size();
32
+
33
+        Assert.assertEquals(expectedOutput, actualOutput);
34
+    }
35
+
36
+    @Test
37
+    public void dealGoFishTest(){
38
+        int expectedOutput = 7;
39
+
40
+        dealer1.deal(7, player2);
41
+        int actualOutput = player2.getPlayerHand().size();
42
+
43
+        Assert.assertEquals(expectedOutput, actualOutput);
44
+    }
45
+
46
+    @Test
47
+    public void pluckTest(){
48
+        int expectedOutput = 1;
49
+
50
+        dealer1.pluck(player1.getPlayerHand());
51
+        int actualOutput = player1.getPlayerHand().size();
52
+
53
+        Assert.assertEquals(expectedOutput, actualOutput);
54
+
55
+    }
56
+}

+ 75
- 0
src/test/java/io/zipcoder/casino/DeckTest.java View File

@@ -0,0 +1,75 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import static org.junit.Assert.*;
9
+
10
+public class DeckTest {
11
+
12
+    private Deck deck;
13
+
14
+
15
+    @Before
16
+    public void setup(){
17
+        deck = new Deck();
18
+        deck.setCards();
19
+    }
20
+
21
+
22
+    @Test
23
+    public void shuffleCards() {
24
+        String before = deck.getCards().toString();
25
+        deck.shuffleCards();
26
+        String after = deck.getCards().toString();
27
+        Assert.assertNotEquals(before, after);
28
+    }
29
+
30
+    @Test
31
+    public void popTest() {
32
+       Card actual = deck.pop();
33
+       Card expected= new Card(Rank.KING, Suit.SPADES);
34
+       Assert.assertEquals(expected.getSuit(),actual.getSuit());
35
+       Assert.assertEquals(expected.getRank(), actual.getRank());
36
+    }
37
+
38
+    @Test
39
+    public void popSizeTest() {
40
+        int startSize = deck.getDeckSize();
41
+        deck.pop();
42
+        int actual = startSize - deck.getDeckSize();
43
+        int expected= 1;
44
+        Assert.assertEquals(expected,actual);
45
+
46
+    }
47
+
48
+
49
+    @Test
50
+    public void peek() {
51
+        Card actual = deck.peek();
52
+        Card expected= new Card(Rank.KING, Suit.SPADES);
53
+        Assert.assertEquals(expected.getSuit(),actual.getSuit());
54
+        Assert.assertEquals(expected.getRank(), actual.getRank());
55
+    }
56
+
57
+    @Test
58
+    public void peekSizeTest() {
59
+        int startSize = deck.getDeckSize();
60
+        deck.peek();
61
+        int actual = startSize - deck.getDeckSize();
62
+        int expected= 0;
63
+        Assert.assertEquals(expected,actual);
64
+
65
+    }
66
+
67
+    @Test
68
+    public void isEmptyTest() {
69
+        boolean actual = deck.isEmpty();
70
+        Assert.assertFalse(actual);
71
+    }
72
+
73
+
74
+}
75
+

+ 25
- 0
src/test/java/io/zipcoder/casino/GoFishPlayerTest.java View File

@@ -0,0 +1,25 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class GoFishPlayerTest {
7
+
8
+    private GoFishPlayer goFishPlayer;
9
+
10
+    @Test
11
+    public void testSetAndGetHand() {
12
+        // Given
13
+        Player player = new Player("Curtis", 36, 100);
14
+        GoFishPlayer goFishPlayer = new GoFishPlayer(player);
15
+        Hand hand = new Hand();
16
+        goFishPlayer.setPlayerHand(hand);
17
+        Hand expectedOutput = hand;
18
+
19
+        // When
20
+        Hand actualOutput = goFishPlayer.getPlayerHand();
21
+
22
+        // Then
23
+        Assert.assertEquals(expectedOutput, actualOutput);
24
+    }
25
+}

+ 163
- 0
src/test/java/io/zipcoder/casino/GoFishTest.java View File

@@ -0,0 +1,163 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import sun.misc.ASCIICaseInsensitiveComparator;
6
+
7
+public class GoFishTest {
8
+    Player William = new Player("William", 18, 0.0);
9
+    GoFish goFish = new GoFish(William);
10
+
11
+    @Test
12
+    public void testUserTurn(){
13
+        //IDK HOW TO TEST
14
+    }
15
+
16
+    @Test
17
+    public void testAiTurn(){
18
+        //IDK HOW TO TEST
19
+    }
20
+
21
+    @Test
22
+    public void testUserMatches(){
23
+        //TEST SIZE
24
+        //MATCH ONE
25
+        //TEST SIZE FOR ONE LESS
26
+        int expected = 0;
27
+        int actual = 0;
28
+
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testAiMatches(){
34
+        //TEST SIZE
35
+        //MATCH ONE
36
+        //TEST SIZE FOR ONE LESS
37
+        int expected = 0;
38
+        int actual = 0;
39
+
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void testUserGuess(){
45
+        //SHOULD RETURN THE INPUT
46
+    }
47
+
48
+    @Test
49
+    public void testAiGuess(){
50
+        //CANT BE TESTED BC IT IS RANDOM
51
+    }
52
+
53
+    @Test
54
+    public void testPlayerGoFish(){
55
+        //GET SIZE OF HAND
56
+        //GO FISH
57
+        //GET SIZE OF HAND + GO FISH
58
+        //SEE IF IT IS ONE MORE
59
+        int expected = 0;
60
+        int actual = 0;
61
+
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void testPlayerGotFish(){
67
+        //GET SIZE OF HAND
68
+        //GOT FISH
69
+        //GET SIZE OF HAND - GOT FISH
70
+        //SEE IF IT IS ONE LESS
71
+        int expected = 0;
72
+        int actual = 0;
73
+
74
+        Assert.assertEquals(expected, actual);
75
+    }
76
+
77
+    @Test
78
+    public void testAiGoFish(){
79
+        //GET SIZE OF HAND
80
+        //GO FISH
81
+        //GET SIZE OF HAND + GO FISH
82
+        //SEE IF IT IS ONE MORE
83
+        int expected = 0;
84
+        int actual = 0;
85
+
86
+        Assert.assertEquals(expected, actual);
87
+    }
88
+
89
+    @Test
90
+    public void testAiGotFish(){
91
+        //GET SIZE OF HAND
92
+        //GOT FISH
93
+        //GET SIZE OF HAND - GOT FISH
94
+        //SEE IF IT IS ONE LESS
95
+        int expected = 0;
96
+        int actual = 0;
97
+
98
+        Assert.assertEquals(expected, actual);
99
+    }
100
+
101
+    @Test
102
+    public void testCheckUserHandSize(){
103
+        //SET HAND SIZE TO ZERO
104
+        //RUN CHECKUSERHANDSIZE()
105
+        //GET HAND SIZE
106
+        //SEE IF THE HAND SIZE IS 7
107
+        int expected = 0;
108
+        int actual = 0;
109
+
110
+        Assert.assertEquals(expected, actual);
111
+    }
112
+
113
+    @Test
114
+    public void testCheckAiHandSize(){
115
+        //SET HAND SIZE TO ZERO
116
+        //RUN CHECKUSERHANDSIZE()
117
+        //GET HAND SIZE
118
+        //SEE IF THE HAND SIZE IS 7
119
+        int expected = 0;
120
+        int actual = 0;
121
+
122
+        Assert.assertEquals(expected, actual);
123
+    }
124
+
125
+    @Test
126
+    public void testAiWinner(){
127
+        //SET AI SCORE TO ONE HIGHER
128
+        goFish.setAiScore(1);
129
+
130
+
131
+        //COMPARE THE SCORES AND SEE IF IT RETURNS AI
132
+    }
133
+
134
+    @Test
135
+    public void testPlayerWinner(){
136
+        //SET PLAYER SCORE TO ONE HIGHER
137
+        goFish.setPlayerScore(1);
138
+
139
+
140
+        //COMPARE THE SCORES AND SEE IF IT RETURNS PLAYER
141
+    }
142
+
143
+    @Test
144
+    public void testResultsAiWinner(){
145
+        //SET AI SCORE TO ONE HIGHER
146
+        goFish.setAiScore(1);
147
+
148
+
149
+        //SHOULD RETURN FALSE
150
+        Assert.assertFalse(goFish.getResult());
151
+    }
152
+
153
+    @Test
154
+    public void testResultsPlayerWinner(){
155
+        //SET PLAYER SCORE TO ONE HIGHER
156
+        goFish.setPlayerScore(1);
157
+
158
+
159
+        //SHOULD RETURN TRUE
160
+        Assert.assertTrue(goFish.getResult());
161
+    }
162
+
163
+}

+ 177
- 0
src/test/java/io/zipcoder/casino/HandTest.java View File

@@ -0,0 +1,177 @@
1
+
2
+package io.zipcoder.casino;
3
+
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
10
+
11
+import static org.junit.Assert.*;
12
+
13
+public class HandTest {
14
+
15
+
16
+    Hand hand;
17
+    Card card1;
18
+    Card card2;
19
+    Card card3;
20
+    Card card4;
21
+    Card card5;
22
+    Card card11;
23
+    Card card12;
24
+    Card card13;
25
+    Card card14;
26
+
27
+
28
+    @Before
29
+    public void setup(){
30
+        hand = new Hand();
31
+        card1 = new Card(Rank.KING, Suit.SPADES);
32
+        card2 = new Card(Rank.TWO, Suit.HEARTS);
33
+        card3 = new Card(Rank.ACE, Suit.DIAMONDS);
34
+        card4 = new Card(Rank.ACE, Suit.SPADES);
35
+        card5 = new Card(Rank.ACE, Suit.HEARTS);
36
+        card11 = new Card(Rank.THREE, Suit.HEARTS);
37
+        card12 = new Card(Rank.THREE, Suit.SPADES);
38
+        card13 = new Card(Rank.THREE, Suit.CLUBS);
39
+        card14 = new Card(Rank.THREE, Suit.DIAMONDS);
40
+
41
+
42
+    }
43
+
44
+    @Test
45
+    public void addTest() {
46
+        hand.add(card1);
47
+        hand.add(card2);
48
+        hand.add(card3);
49
+        int actual = hand.size();
50
+        int expected = 3;
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void getHandTest() {
56
+        hand.add(card1);
57
+        hand.add(card2);
58
+        hand.add(card3);
59
+        ArrayList<Card> expected = new ArrayList<Card>(Arrays.asList(card1, card2,card3));
60
+        ArrayList<Card> actual = hand.getHand();
61
+        Assert.assertEquals(expected, actual);
62
+    }
63
+
64
+    @Test
65
+    public void numberOfDuplicatesTest() {
66
+        hand.add(card1);
67
+        hand.add(card2);
68
+        hand.add(card3);
69
+        hand.add(card4);
70
+        hand.add(card5);
71
+        int expected = 1;
72
+        int actual = hand.numberOfDuplicates();
73
+        Assert.assertEquals(expected,actual);
74
+    }
75
+
76
+    @Test
77
+    public void numberOfDuplicatesBigTest() {
78
+        hand.add(card1);
79
+        hand.add(card2);
80
+        hand.add(card3);
81
+        hand.add(card4);
82
+        hand.add(card5);
83
+        hand.add(card11);
84
+        hand.add(card12);
85
+        hand.add(card13);
86
+        hand.add(card14);
87
+        int expected = 3;
88
+        int actual = hand.numberOfDuplicates();
89
+        Assert.assertEquals(expected,actual);
90
+    }
91
+
92
+    @Test
93
+    public void containsTestTrue() {
94
+        hand.add(card1);
95
+        hand.add(card2);
96
+        hand.add(card3);
97
+        boolean actual= hand.contains(card2);
98
+        Assert.assertTrue(actual);
99
+    }
100
+
101
+    @Test
102
+    public void containsTestFalse() {
103
+        hand.add(card1);
104
+        hand.add(card3);
105
+        boolean actual= hand.contains(card2);
106
+        Assert.assertFalse(actual);
107
+    }
108
+
109
+    @Test
110
+    public void removeDuplicatesTest() {
111
+        hand.add(card1);
112
+        hand.add(card2);
113
+        hand.add(card3);
114
+        hand.add(card4);
115
+        hand.removeDuplicates();
116
+        String expected = "TWOHEARTS KINGSPADES ";
117
+        String actual = hand.toString();
118
+        Assert.assertEquals(expected, actual);
119
+    }
120
+    @Test
121
+    public void removeDuplicatesBigTest() {
122
+        hand.add(card1);
123
+        hand.add(card2);
124
+        hand.add(card3);
125
+        hand.add(card4);
126
+        hand.add(card5);
127
+        hand.add(card11);
128
+        hand.add(card12);
129
+        hand.add(card13);
130
+        hand.add(card14);
131
+        hand.removeDuplicates();
132
+        String expected = "ACEDIAMONDS TWOHEARTS KINGSPADES ";
133
+        String actual = hand.toString();
134
+        Assert.assertEquals(expected,actual);
135
+
136
+    }
137
+
138
+    @Test
139
+    public void toStringTest() {
140
+        hand.add(card1);
141
+        hand.add(card2);
142
+        String actual = hand.toString();
143
+        String expected = "KINGSPADES TWOHEARTS ";
144
+
145
+    }
146
+
147
+    @Test
148
+    public void getNumberOfOccurrences() {
149
+        hand.add(card1);
150
+        hand.add(card2);
151
+        hand.add(card3);
152
+        hand.add(card4);
153
+        int actual = hand.getNumberOfRankOccurrences(card3);
154
+        int expected = 2;
155
+        Assert.assertEquals(expected, actual);
156
+    }
157
+
158
+
159
+
160
+
161
+    @Test
162
+    public void getTotalValue(){
163
+        hand.add(card1);
164
+        hand.add(card2);
165
+        hand.add(card3);
166
+        hand.add(card4);
167
+        hand.add(card5);
168
+        hand.add(card11);
169
+        hand.add(card12);
170
+        hand.add(card13);
171
+        hand.add(card14);
172
+        int actual = hand.getTotal();
173
+        int expected =27;
174
+        Assert.assertEquals(expected, actual);
175
+    }
176
+}
177
+

+ 34
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java View File

@@ -0,0 +1,34 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PlayerTest {
7
+
8
+    @Test
9
+    public void testGetName() {
10
+        // Given
11
+        Player player = new Player("Curtis", 37, 500);
12
+        String expectedOutput = "Curtis";
13
+
14
+        // When
15
+        String actualOutput = player.getName();
16
+
17
+        // Then
18
+        Assert.assertEquals(expectedOutput, actualOutput);
19
+
20
+    }
21
+
22
+    @Test
23
+    public void testGetAge() {
24
+        // Given
25
+        Player player = new Player("Curtis", 37, 500);
26
+        int expectedOutput = 37;
27
+
28
+        // When
29
+        int actualOutput = player.getAge();
30
+
31
+        // Then
32
+        Assert.assertEquals(expectedOutput, actualOutput);
33
+    }
34
+}

+ 37
- 0
src/test/java/io/zipcoder/casino/RoulettePlayerTest.java View File

@@ -0,0 +1,37 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class RoulettePlayerTest {
7
+
8
+    @Test
9
+    public void testGamble() {
10
+        // Given
11
+        Player player = new Player("Curtis", 36, 100);
12
+        RoulettePlayer roulettePlayer = new RoulettePlayer(player);
13
+        double expectedOutput = 100 - 25;
14
+
15
+        // When
16
+        roulettePlayer.gamble(25);
17
+        double actualOutput = 75;
18
+
19
+        // Then
20
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
21
+    }
22
+
23
+    @Test
24
+    public void testGamble2() {
25
+        // Given
26
+        Player player = new Player("Curtis", 36, 100);
27
+        RoulettePlayer roulettePlayer = new RoulettePlayer(player);
28
+        double expectedOutput = 100;
29
+
30
+        // When
31
+        roulettePlayer.gamble(125);
32
+        double actualOutput = 100;
33
+
34
+        // Then
35
+        Assert.assertEquals(expectedOutput, actualOutput, 0.01);
36
+    }
37
+}