-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
902c33f
commit fb771e8
Showing
10 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>BlackJackProject</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.skilldistillery.cards; | ||
|
||
import java.util.Objects; | ||
|
||
public class Card { | ||
private Rank rank; | ||
private Suit suit; | ||
|
||
public Card(Rank rank, Suit suit) { | ||
this.rank = rank; | ||
this.suit = suit; | ||
} | ||
|
||
public int getValue() { | ||
return this.rank.getValue(); | ||
} | ||
|
||
public Rank getRank() { | ||
return rank; | ||
} | ||
|
||
public Suit getSuit() { | ||
return suit; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return rank + " of " + suit; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(rank, suit); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
Card other = (Card) obj; | ||
return rank == other.rank && suit == other.suit; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.skilldistillery.cards; | ||
|
||
public class CardTest { | ||
public static void main(String[] args) { | ||
Rank[] ranks = Rank.values(); | ||
for(int i=0; i<ranks.length; i++) { | ||
System.out.println(ranks[i] + " " + ranks[i].getValue()); | ||
} | ||
|
||
for(Suit s : Suit.values()){ | ||
System.out.println(s); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.skilldistillery.cards; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class DealingTest { | ||
|
||
public static void main(String[] args) { | ||
DealingTest dealing = new DealingTest(); | ||
dealing.deal(); | ||
|
||
|
||
} | ||
|
||
public void deal() { | ||
// get a deck of cards | ||
Deck deck = new Deck(); | ||
|
||
// call shuffle method to shuffle deck | ||
deck.shuffleDeck(); | ||
|
||
// ask the user "how many cards?" | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("How many cards do you want?"); | ||
int howMany = sc.nextInt(); | ||
sc.nextLine(); | ||
|
||
List<Card> userHand = new ArrayList<>(); | ||
int handTotal = 0; | ||
|
||
// deal input amount using deal method, one card/time | ||
for (int numCard = 0; (numCard < howMany) && (deck != null) && (numCard < 52) && (deck.checkDeckSize() > 0 ); numCard++) { | ||
Card dealtCard = deck.dealCard(); | ||
|
||
// user puts dealt card in hand | ||
userHand.add(dealtCard); | ||
|
||
// the user adds up the cards, based on the rank | ||
handTotal += dealtCard.getValue(); | ||
|
||
|
||
// have the user show their hand | ||
System.out.println("Player total of hand: " + handTotal); | ||
for (Card card : userHand) { | ||
System.out.println(card); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.skilldistillery.cards; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Deck { | ||
private List<Card> deck = new ArrayList<>(); | ||
|
||
public Deck() { | ||
for (Suit suit : Suit.values()) { | ||
for (Rank rank : Rank.values()) { | ||
Card card = new Card(rank, suit); | ||
deck.add(card); | ||
} | ||
} | ||
|
||
} | ||
|
||
public int checkDeckSize() { | ||
return deck.size(); | ||
} | ||
|
||
public void shuffleDeck() { | ||
Collections.shuffle(deck); | ||
|
||
} | ||
|
||
public Card dealCard() { | ||
Card card = deck.remove(0); | ||
return card; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.skilldistillery.cards; | ||
|
||
public enum Rank { | ||
TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11); | ||
|
||
private int value; | ||
|
||
Rank(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
|
||
} | ||
|
||
// public String toString() { | ||
// return "" + value; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.skilldistillery.cards; | ||
|
||
public enum Suit { | ||
HEARTS("Hearts"), SPADES("Spades"), CLUBS("Clubs"), DIAMONDS("Diamonds"); | ||
|
||
private String name; | ||
|
||
Suit(String name) { | ||
this.name = name; | ||
|
||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String toString() { | ||
return name; | ||
} | ||
|
||
|
||
} |