From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- Java/BlackJack/Card.java | 250 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 Java/BlackJack/Card.java (limited to 'Java/BlackJack/Card.java') diff --git a/Java/BlackJack/Card.java b/Java/BlackJack/Card.java new file mode 100644 index 0000000..f4b2df4 --- /dev/null +++ b/Java/BlackJack/Card.java @@ -0,0 +1,250 @@ +public class Card { + + // data member + private int facePointValue; + private String faceValue; + private int points; + private String suit; + private int suitPointValue; + + + + // Constructors + //accepts suit and face + public Card (String inFace, String inSuit) { + + switch(inFace){ //Reasoning for the switch is that working with strings as values in a comparision game will only casue problems, it must be converted to a sensable value + case "King": //all face cards are 10. 10 is also 10 (for obvious reasons) + case "king": + case "Joker": + case "joker": + case "Queen": + case "queen": + case "Jack": + case "jack": + case "10": + case "ten": + case "Ten": + facePointValue = 10; + break; + //these comparisions are the worst, but its the best way I could figure out accounting for all reasonable inputs without using regex + case "9": + case "nine": + case "Nine": + facePointValue = 9; + break; + + case "8": + case "eight": + case "Eight": + facePointValue = 8; + break; + + case "7": + case "seven": + case "Seven": + facePointValue = 7; + break; + + case "6": + case "six": + case "Six": + facePointValue = 6; + break; + + case "5": + case "five": + case "Five": + facePointValue = 5; + break; + + case "4": + case "four": + case "Four": + facePointValue = 4; + break; + + case "3": + case "three": + case "Three": + facePointValue = 3; + break; + case "2": + case "two": + case "Two": + facePointValue = 2; + break; + + case "1": + case "one": + case "One": + case "Ace": + case "ace": + facePointValue = 1; + break; + default: + System.out.println("User Input was Invalid! " + inFace + " Is not a valad card!"); + System.exit(1); + + } + + faceValue = inFace; //since all of the above is just for value finding and will crash if breaks, might as well just get inFace as the value. + switch(inSuit){ + case "heart": + case "hearts": + case "Heart": + case "Hearts": + suitPointValue = 4; + break; + case "club": + case "clover": + case "Club": + case "Clover": + suitPointValue = 3; + break; + case "Diamond": + case "diamond": + suitPointValue = 2; + break; + case "spade": + case "spear": + case "shovel": + case "Spade": + case "Spear": + case "Shovel": + suitPointValue = 1; + break; + default: + System.out.println("User Input was Invalid! " + inSuit + " Is not a valad card!"); + + System.exit(1); + } + suit = inSuit; //ditto reasoning of last comment + + } +//no suit or face? assume 4 of clovers + public Card() { + suitPointValue = 3; + facePointValue = 4; + suit = "Clover"; + faceValue = "4"; + } + +// set & return +// set + +//return +public String getFaceValue(){ +return figureName(facePointValue); +} + +public String getFaceSuit(){ +return figureSuit(suitPointValue); +} + +public int getFaceNumericValue(){ +return facePointValue; +} + +public int getSuitNumericValue(){ +return suitPointValue; +} + + + public String figureName(int input) { + switch(input){ + + case 1: + return "One"; + + + case 2: + return "Two"; + + + case 3: + return "Three"; + + + case 4: + return "Four"; + + case 5: + return "Five"; + + case 6: + return "Six"; + + case 7: + return "Seven"; + + case 8: + return "Eight"; + + case 9: + return "Nine"; + + case 10: + return "Ten"; + + case 11: + return "Jack"; + + case 12: + return "Queen"; + + case 13: + return "King"; + + case 14: + return "Joker"; + + default: + System.out.println("figureName does not take " + input + "as a valid input!"); + return null; + } + + } + + public String figureSuit(int input) { + switch(input){ + case 1: + return "Hearts"; + + case 2: + return "Clovers"; + + case 3: + return "Diamonds"; + + case 4: + return "Spade"; + default: + System.out.println("figureSuit does not take" + input + "as a valid input!"); + return null; + + + } + } + + public String compareCardValue(String card1Name, int card1Face, int card1Suit, String card2Name, int card2Face, int card2Suit) { + + if(card1Face == card2Face){ + if(card1Suit > card2Suit){ + return card1Name; + } else { + return card2Name; + } + + } + + if (card1Face > card2Face) { + return card1Name; + } else { + return card2Name; + } + } + +} + + -- cgit v1.2.3