Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Deck{
- card[] cards;
- int numJokers;
- int numStandard;
- /* creates a deck of 54 cards as described in the Cards problem
- * (52 cards that are in the standard deck of cards plus two jokers)
- */
- public Deck(){
- /* create a deck with specified number of copies of the
- * standard deck (52 cards) and with the specified
- * number of jokers
- *
- * Both inputs must be non-negative
- */
- card[] counter = new card[54];
- this.numJokers = 2;
- this.numStandard = 54;
- int index = 0;
- for ( int i = 0; i <= 3; i++ ) {
- for ( int j = 2; j <= 15; j++ ) {
- counter[index] = new Card(counter[index].RANKS[i], counter[index].SUITS[j]);
- index += 1;
- }
- }
- counter[52] = new Card(counter[52].RANKS[1], counter[52].SUITS[4]);
- counter[53] = new Card(counter[53].RANKS[1], counter[53].SUITS[4]);
- }
- public Deck(int numStandard, int numJokers){
- this.numStandard = numStandard;
- this.numJokers = numJokers;
- int cardindex = 0;
- Card[] counter = new Card[(numStandard*52)+numJokers];
- }
- /* returns the number of cards in the deck */
- public int numCards(){
- return (numStandard*52)+numJokers;
- }
- /* returns all the cards in the deck without modifying the deck
- * the ordering in the array is the order of the cards at this
- * given time */
- public Card[] getCards(){
- return this.counter;
- }
- /* return the top card of the deck without modifying the deck */
- public Card peek(){
- return this.counter[0];
- }
- /* remove the top card from the deck and return it */
- public Card pop(){
- Card[] newdeck = new Card[this.numCards()-1];
- Card top = this.cards[this.numCards()-1];
- for( int i = 0; i <this.cards.length-1; i++){
- newcards[i] = this.cards[i] ;
- }
- this.cards = newcards;
- return top;}
- }
- /* randomly shuffle the order of the cards in the deck */
- public void shuffleDeck(){}
- for ( int i = card.length-1; i > 0; i-- ) {
- int rand = (int)(Math.random()*(i+1));
- Card temp = this.cards[i];
- this.cards[i] = this.cards[rand];
- this.cards[rand] = temp;
- }
- /* sorts the deck so that cards are in the order
- * specified in the Cards problem (low cards first)
- */
- public void sortDeck(){
- java.util.Arrays.sort(this.card);
- }
- public static void main(String args[]) {
- Deck standard = new Deck(1,0);
- System.out.println(standard.numCards());
- //System.out.println(standard.getCards());
- System.out.println(java.util.Arrays.toString(standard.getCards()));
- standard.shuffleDeck();
- System.out.println(" ");
- System.out.println(java.util.Arrays.toString(standard.getCards()));
- standard.sortDeck();
- standard.pop();
- System.out.println(" ");
- System.out.println(java.util.Arrays.toString(standard.getCards()));
- //java.util.Arrays.toString(standard.getCards());
- // standard.sortDeck();
- // Card c = standard.pop();
- // System.out.println(standard.numCards());
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement