Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. import java.util.Random;
  2. public class Deck{
  3.  
  4. card[] cards;
  5. int numJokers;
  6. int numStandard;
  7.  
  8. /* creates a deck of 54 cards as described in the Cards problem
  9. * (52 cards that are in the standard deck of cards plus two jokers)
  10. */
  11. public Deck(){
  12.  
  13. /* create a deck with specified number of copies of the
  14. * standard deck (52 cards) and with the specified
  15. * number of jokers
  16. *
  17. * Both inputs must be non-negative
  18. */
  19. card[] counter = new card[54];
  20. this.numJokers = 2;
  21. this.numStandard = 54;
  22.  
  23. int index = 0;
  24. for ( int i = 0; i <= 3; i++ ) {
  25. for ( int j = 2; j <= 15; j++ ) {
  26. counter[index] = new Card(counter[index].RANKS[i], counter[index].SUITS[j]);
  27. index += 1;
  28. }
  29. }
  30.  
  31. counter[52] = new Card(counter[52].RANKS[1], counter[52].SUITS[4]);
  32. counter[53] = new Card(counter[53].RANKS[1], counter[53].SUITS[4]);
  33. }
  34.  
  35. public Deck(int numStandard, int numJokers){
  36. this.numStandard = numStandard;
  37. this.numJokers = numJokers;
  38.  
  39. int cardindex = 0;
  40. Card[] counter = new Card[(numStandard*52)+numJokers];
  41.  
  42. }
  43.  
  44. /* returns the number of cards in the deck */
  45. public int numCards(){
  46. return (numStandard*52)+numJokers;
  47. }
  48.  
  49.  
  50. /* returns all the cards in the deck without modifying the deck
  51. * the ordering in the array is the order of the cards at this
  52. * given time */
  53. public Card[] getCards(){
  54. return this.counter;
  55. }
  56.  
  57.  
  58. /* return the top card of the deck without modifying the deck */
  59. public Card peek(){
  60. return this.counter[0];
  61. }
  62.  
  63.  
  64. /* remove the top card from the deck and return it */
  65. public Card pop(){
  66. Card[] newdeck = new Card[this.numCards()-1];
  67. Card top = this.cards[this.numCards()-1];
  68. for( int i = 0; i <this.cards.length-1; i++){
  69. newcards[i] = this.cards[i] ;
  70. }
  71. this.cards = newcards;
  72.  
  73. return top;}
  74. }
  75.  
  76.  
  77. /* randomly shuffle the order of the cards in the deck */
  78. public void shuffleDeck(){}
  79. for ( int i = card.length-1; i > 0; i-- ) {
  80. int rand = (int)(Math.random()*(i+1));
  81. Card temp = this.cards[i];
  82. this.cards[i] = this.cards[rand];
  83. this.cards[rand] = temp;
  84. }
  85.  
  86. /* sorts the deck so that cards are in the order
  87. * specified in the Cards problem (low cards first)
  88. */
  89. public void sortDeck(){
  90. java.util.Arrays.sort(this.card);
  91. }
  92.  
  93. public static void main(String args[]) {
  94.  
  95. Deck standard = new Deck(1,0);
  96. System.out.println(standard.numCards());
  97. //System.out.println(standard.getCards());
  98.  
  99.  
  100.  
  101. System.out.println(java.util.Arrays.toString(standard.getCards()));
  102. standard.shuffleDeck();
  103.  
  104. System.out.println(" ");
  105.  
  106. System.out.println(java.util.Arrays.toString(standard.getCards()));
  107. standard.sortDeck();
  108.  
  109. standard.pop();
  110.  
  111. System.out.println(" ");
  112.  
  113. System.out.println(java.util.Arrays.toString(standard.getCards()));
  114.  
  115.  
  116.  
  117. //java.util.Arrays.toString(standard.getCards());
  118. // standard.sortDeck();
  119. // Card c = standard.pop();
  120. // System.out.println(standard.numCards());
  121. //
  122.  
  123.  
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement