Akeem Cherry 6 jaren geleden
bovenliggende
commit
02d0615da7

+ 10
- 0
src/main/java/io/zipcoder/casino/BlackjackPlayer.java Bestand weergeven

@@ -0,0 +1,10 @@
1
+package io.zipcoder.casino;
2
+
3
+public class BlackjackPlayer extends Player{
4
+
5
+
6
+    public BlackjackPlayer(String name, double moneyStartedWith) {
7
+
8
+        super(name, moneyStartedWith);
9
+    }
10
+}

+ 0
- 23
src/main/java/io/zipcoder/casino/Card.java Bestand weergeven

@@ -1,23 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class Card {
4
-    private Suit suit;
5
-    private Rank rank;
6
-
7
-    public Card(Suit suit, Rank rank) {
8
-        this.suit = suit;
9
-        this.rank = rank;
10
-    }
11
-
12
-    public Suit getSuit() {
13
-        return suit;
14
-    }
15
-
16
-    public Rank getRank() {
17
-        return rank;
18
-    }
19
-
20
-    public Integer getValue(){
21
-        return rank.primaryValue;
22
-    }
23
-}

+ 0
- 5
src/main/java/io/zipcoder/casino/Casino.java Bestand weergeven

@@ -1,5 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-
4
-public class Casino {
5
-}

+ 16
- 0
src/main/java/io/zipcoder/casino/Dealer.java Bestand weergeven

@@ -0,0 +1,16 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Dealer extends Player {
4
+
5
+    public Dealer(String name, double moneyStartedWith) {
6
+        super(name, moneyStartedWith);
7
+    }
8
+
9
+    public void dealCards(Player player, Card card){
10
+
11
+    }
12
+
13
+    public void takeBet(Player player, double money){
14
+
15
+    }
16
+}

+ 0
- 58
src/main/java/io/zipcoder/casino/Deck.java Bestand weergeven

@@ -1,58 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import java.util.ArrayList;
4
-import java.util.Collections;
5
-import java.util.List;
6
-import java.util.Stack;
7
-
8
-public class Deck {
9
-
10
-    private static Suit Suit;
11
-    private static Rank Rank;
12
-    private Stack<Card> deck;
13
-
14
-
15
-
16
-
17
-    public Deck(){
18
-        this.deck = new Stack<Card>();
19
-        for (Suit suit : Suit.values()){
20
-            for (Rank rank : Rank.values()){
21
-                deck.push(new Card(suit, rank));
22
-            }
23
-        }
24
-    }
25
-
26
-
27
-
28
-    public Integer size(){
29
-
30
-        return deck.size();
31
-    }
32
-
33
-    public Card popCard(){
34
-
35
-        return deck.pop();
36
-    }
37
-
38
-    public Card pushCard(Card card){
39
-
40
-        return deck.push(card);
41
-    }
42
-
43
-    public boolean isEmpty(){
44
-        return deck.isEmpty();
45
-
46
-    }
47
-
48
-    public void shuffleDeck(Stack<Card> deck){
49
-
50
-        Collections.shuffle(deck);
51
-
52
-    }
53
-
54
-//    public void peek(Card card){
55
-//        return deck.peek();
56
-//
57
-//}
58
-}

+ 55
- 0
src/main/java/io/zipcoder/casino/Player.java Bestand weergeven

@@ -0,0 +1,55 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Player {
4
+
5
+    private String name;
6
+
7
+    private Hand hand;
8
+
9
+    private Wallet wallet;
10
+    private double wager;
11
+
12
+    public Player(String name, double moneyStartedWith) {
13
+
14
+        this.hand = new Hand();
15
+
16
+        this.name = name;
17
+
18
+        this.wallet = new Wallet(moneyStartedWith);
19
+    }
20
+
21
+    public void addCard(Card card) {
22
+
23
+        hand.add(card);
24
+    }
25
+
26
+    public Hand getHand() {
27
+
28
+        return hand;
29
+    }
30
+
31
+    public void setHand(Hand hand) {
32
+
33
+        this.hand = hand;
34
+    }
35
+
36
+    public String getName() {
37
+
38
+        return name;
39
+    }
40
+
41
+    public void setWager(double money) {
42
+        this.wager = money;
43
+        wallet.takeMoney(money);
44
+    }
45
+
46
+    public double getWalletAmount() {
47
+        return wallet.getCurrentAmount();
48
+    }
49
+
50
+    public double getWager() {
51
+
52
+        return wager;
53
+    }
54
+
55
+}

+ 0
- 31
src/main/java/io/zipcoder/casino/Rank.java Bestand weergeven

@@ -1,31 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public enum Rank {
4
-    Ace(1,11),
5
-    Two(2),
6
-    Three(3),
7
-    Four(4),
8
-    Five(5),
9
-    Six(6),
10
-    Seven(7),
11
-    Eight(8),
12
-    Nine(9),
13
-    Ten(10),
14
-    Jack(10),
15
-    Queen(10),
16
-    King(10);
17
-
18
-    final Integer primaryValue;
19
-    final Integer secondaryValue;
20
-
21
-    Rank(Integer primaryValue, Integer secondaryValue) {
22
-        this.primaryValue = primaryValue;
23
-        this.secondaryValue = secondaryValue;
24
-
25
-    }
26
-
27
-    Rank(Integer primaryValue) {
28
-        this.primaryValue = primaryValue;
29
-        this.secondaryValue = primaryValue;
30
-    }
31
-}

+ 0
- 14
src/main/java/io/zipcoder/casino/Suit.java Bestand weergeven

@@ -1,14 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public enum  Suit {
4
-    SPADE("♤"),
5
-    HEART("♥"),
6
-    CLUB("♧"),
7
-    DIAMOND("♢");
8
-
9
-    private final String symbol;
10
-
11
-    Suit(String symbol) {
12
-        this.symbol = symbol;
13
-    }
14
-}

+ 0
- 23
src/main/java/io/zipcoder/casino/Wallet.java Bestand weergeven

@@ -1,23 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class Wallet {
4
-
5
-    private double money;
6
-    private Integer id;
7
-
8
-    public double getMoney(double money) {
9
-        return money;
10
-    }
11
-
12
-    public double addMoney(double money, double amountAwarded){
13
-        money += amountAwarded;
14
-
15
-        return money;
16
-    }
17
-
18
-    public double takeMoney(double money, double amountRemoved){
19
-        money -= amountRemoved;
20
-
21
-        return money;
22
-    }
23
-}

+ 45
- 0
src/test/java/io/zipcoder/casino/BlackjackPlayerTest.java Bestand weergeven

@@ -0,0 +1,45 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.BlackjackPlayer;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+public class BlackjackPlayerTest {
9
+
10
+    BlackjackPlayer blackjackPlayer;
11
+
12
+
13
+    @Before
14
+    public void setup(){
15
+
16
+        blackjackPlayer  = new BlackjackPlayer("Xzavia", 200.00);
17
+
18
+    }
19
+
20
+    @Test
21
+    public void setWagerTest() {
22
+
23
+        //When
24
+        double actual = 100.00;
25
+
26
+        blackjackPlayer.setWager(100.00);
27
+
28
+        double expected = blackjackPlayer.getWager();
29
+
30
+        //Then
31
+        Assert.assertEquals(expected, actual, 0);
32
+    }
33
+
34
+    @Test
35
+    public void getNameTest() {
36
+
37
+        String expected = "Tommy";
38
+
39
+        String actual = blackjackPlayer.getName();
40
+
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+
45
+}

+ 0
- 5
src/test/java/io/zipcoder/casino/CasinoTest.java Bestand weergeven

@@ -1,5 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-
4
-public class CasinoTest {
5
-}

+ 83
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java Bestand weergeven

@@ -0,0 +1,83 @@
1
+package io.zipcoder.casino;
2
+
3
+import io.zipcoder.casino.*;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import java.util.List;
9
+
10
+public class PlayerTest {
11
+
12
+    Player xzavia;
13
+
14
+    @Before
15
+    public void setup(){
16
+
17
+        xzavia = new Player("Xzavia", 10_000.00);
18
+    }
19
+
20
+    @Test
21
+    public void addCardTest() {
22
+
23
+        //Given
24
+
25
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
26
+
27
+        //When
28
+        xzavia.addCard(expected);
29
+        Card actual = xzavia.getHand().getCards().get(0);
30
+
31
+        //Then
32
+        Assert.assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+
37
+    public void getHandTest() {
38
+
39
+        //Given
40
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
41
+        Hand hand = new Hand();
42
+
43
+        //When
44
+        hand.add(expected);
45
+        List<Card> cards = hand.getCards();
46
+
47
+        //Then
48
+        Assert.assertTrue(cards.contains(expected));
49
+
50
+    }
51
+
52
+    @Test
53
+
54
+    public void setHandTest() {
55
+
56
+        //Given
57
+        Card expected = new Card(Suit.SPADE, Rank.Jack);
58
+
59
+        Hand hand = new Hand();
60
+
61
+        //When
62
+
63
+
64
+        //Then
65
+
66
+    }
67
+
68
+    @Test
69
+    public void getWalletAmountAfterWager(){
70
+
71
+        //When
72
+        xzavia.setWager(1000.00);
73
+
74
+        double expected = 9000.00;
75
+
76
+        double actual = xzavia.getWalletAmount();
77
+
78
+        //Then
79
+        Assert.assertEquals(expected,actual,0);
80
+
81
+
82
+    }
83
+}

+ 0
- 40
src/test/java/io/zipcoder/casino/TestCard.java Bestand weergeven

@@ -1,40 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-
6
-public class TestCard {
7
-
8
-    @Test
9
-    public void getSuitTest(){
10
-        //Given
11
-        Card aceOfSpade = new Card(Suit.SPADE, Rank.Ace);
12
-        Suit expectedSuit = Suit.SPADE;
13
-        //When
14
-        Suit actualSuit = aceOfSpade.getSuit();
15
-        //Then
16
-        Assert.assertEquals(expectedSuit, actualSuit);
17
-    }
18
-
19
-    @Test
20
-    public void getRankTest(){
21
-        //Given
22
-        Card twoOfHearts = new Card(Suit.HEART, Rank.Two);
23
-        Rank expectedRank = Rank.Two;
24
-        //When
25
-        Rank actualRank = twoOfHearts.getRank();
26
-        //Then
27
-        Assert.assertEquals(expectedRank, actualRank);
28
-    }
29
-
30
-    @Test
31
-    public void getValueTest(){
32
-        //Given
33
-        Card jackOfClub = new Card(Suit.CLUB, Rank.Jack);
34
-        Integer expectedValue = 10;
35
-        //When
36
-        Integer actualValue = Rank.Jack.primaryValue;
37
-        //Then
38
-        Assert.assertEquals(expectedValue, actualValue);
39
-    }
40
-}

+ 0
- 40
src/test/java/io/zipcoder/casino/TestDeck.java Bestand weergeven

@@ -1,40 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import org.junit.Test;
4
-
5
-import java.util.Stack;
6
-
7
-
8
-public class TestDeck {
9
-
10
-    @Test
11
-    public void testDeckSize(){
12
-        //Given
13
-        Stack<Card> deckSize = new Stack<Card>();
14
-        Integer expectedSize = deckSize
15
-        //When
16
-
17
-        //Then
18
-    }
19
-
20
-    @Test
21
-    public void testPopCard(){
22
-        //Given
23
-        //When
24
-        //Then
25
-    }
26
-
27
-    @Test
28
-    public void testPushCard(){
29
-        //Given
30
-        //When
31
-        //Then
32
-    }
33
-
34
-    @Test
35
-    public void testDeckIsEmpty(){
36
-        //Given
37
-        //When
38
-        //Then
39
-    }
40
-}

+ 0
- 41
src/test/java/io/zipcoder/casino/TestWallet.java Bestand weergeven

@@ -1,41 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-
6
-public class TestWallet {
7
-
8
-    @Test
9
-    public void testAddMoney(){
10
-        //Given
11
-        Wallet joeWallet = new Wallet();
12
-        double expectedMoney = 120.00;
13
-        //When
14
-        double actualMoney = joeWallet.addMoney(108.00,12.00);
15
-        //Then
16
-        Assert.assertEquals(expectedMoney, actualMoney, 0);
17
-    }
18
-
19
-    @Test
20
-    public void testTakeMoney(){
21
-        //Given
22
-        Wallet joeWallet = new Wallet();
23
-        double expectedMoney = 12.00;
24
-        //When
25
-        double actualMoney = joeWallet.takeMoney(24.00,12.00);
26
-        //Then
27
-        Assert.assertEquals(expectedMoney, actualMoney, 0);
28
-    }
29
-
30
-    @Test
31
-    public void testGetMoney(){
32
-        //Given
33
-        Wallet joeWallet = new Wallet();
34
-        double expectedMoney = 12.00;
35
-        //When
36
-        double actualMoney = joeWallet.getMoney(12.00);
37
-        //Then
38
-        Assert.assertEquals(expectedMoney, actualMoney, 0);
39
-    }
40
-
41
-}