Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Shumway42 committed Oct 29, 2021
1 parent 902c33f commit fb771e8
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .classpath
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>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
bin
17 changes: 17 additions & 0 deletions .project
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>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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
50 changes: 50 additions & 0 deletions src/com/skilldistillery/cards/Card.java
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;
}



}
14 changes: 14 additions & 0 deletions src/com/skilldistillery/cards/CardTest.java
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);
}
}
}
55 changes: 55 additions & 0 deletions src/com/skilldistillery/cards/DealingTest.java
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);

}


}

}

}
34 changes: 34 additions & 0 deletions src/com/skilldistillery/cards/Deck.java
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;
}

}
20 changes: 20 additions & 0 deletions src/com/skilldistillery/cards/Rank.java
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;
// }
}
22 changes: 22 additions & 0 deletions src/com/skilldistillery/cards/Suit.java
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;
}


}

0 comments on commit fb771e8

Please sign in to comment.