Posted By

mille9393 on 09/25/18


Tagged


Versions (?)

asdasdasd


 / Published in: Java
 

asd

  1. public class Card {
  2.  
  3. private String face; //Face of card, i.e "King" & "Queen"
  4. private String suit; //Suit of card, i.e "Hearts" & "diamonds"
  5.  
  6. public Card (String cardFace, String cardSuit){ //Constructor which initializes card's face and suit
  7. this.face = cardFace;
  8. this.suit = cardSuit;
  9. }
  10.  
  11. public String toString(){ //return String representation of Card
  12. return face + " of " + suit;
  13. }
  14.  
  15. }
  16.  
  17.  
  18.  
  19. import java.util.ArrayList;
  20. import java.util.Random;
  21. import java.util.Collections;
  22.  
  23.  
  24. public class DeckOfCards {
  25.  
  26. private Card[] deck;
  27. private static final Random random = new Random();
  28.  
  29. private int currentCard; //index of next Card to be deal (0-51)
  30. private static final int NUMBER_OF_CARDS = 52; //Constant number of cards
  31.  
  32. public DeckOfCards(){
  33.  
  34. String [] faces = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack","Queen", "King"};
  35. String [] suits = {"Hearts", "Diamonds", "Clubs", "Spades"};
  36.  
  37. deck = new Card [NUMBER_OF_CARDS]; // create array with Cards (52)
  38. currentCard = 0;
  39.  
  40. //Populate deck with Cards
  41. for(int count = 0; count < deck.length; count++)
  42. deck [count] =
  43. new Card(faces [count % 13], suits [count / 13]);
  44. }
  45.  
  46. public void shuffleDeck(){
  47. currentCard = 0;
  48.  
  49. for (int first = 0; first < deck.length; first++){
  50.  
  51. int second = random.nextInt(NUMBER_OF_CARDS); //Select a random card from number 0-51 (Number_of_cards)
  52.  
  53. //Loops through all the cards and swaps it with the "Second" card which is randomly chosen card from hte same list.
  54. Card temp = deck[first];
  55. deck [first] = deck [second];
  56. deck [second] = temp;
  57. }
  58. }
  59.  
  60. public void getKortlek(){
  61. for(Card k : deck){
  62. System.out.println(k);
  63. }
  64. }
  65.  
  66. public Card dealCard(){
  67. if (currentCard < deck.length){
  68.  
  69. return deck[currentCard++];
  70. } else {
  71. return null;
  72. }
  73. }
  74.  
  75. }
  76.  
  77.  
  78. public class BlackJackGame {
  79.  
  80. public static void main(String[] args) {
  81.  
  82. DeckOfCards deck1 = new DeckOfCards();
  83. deck1.shuffleDeck();
  84. for( int i = 1; i <= 52; i++){
  85. System.out.printf("%-19s", deck1.dealCard() );
  86. if( i % 4 == 0) {
  87. System.out.println();
  88. }
  89. }
  90. }
  91. }
  92.  
  93.  
  94. import java.util.ArrayList;
  95. public class Player {
  96.  
  97. private String phoneNr;
  98. private String nickName;
  99. ArrayList<DeckOfCards> playerHand = new ArrayList<>();
  100.  
  101. public Player (String name, String mobileNr){
  102. this.nickName = name;
  103. this.phoneNr = mobileNr;
  104. }
  105.  
  106. public String getPhoneNr() {
  107. return phoneNr;
  108. }
  109.  
  110. public String getNickName() {
  111. return nickName;
  112. }
  113.  
  114. public void addCard()
  115.  
  116.  
  117. }

Report this snippet  

You need to login to post a comment.