//
// You don't need to worry about this code... but if you are curious read on!
//



// Class Interface
//
// If you want to use this class, you look at the class interface to learn how
// to access the members and methods of the class.  Good member/method names
// and pre/post conditions help you figure this out.
//
// This class models a deck of cards.  It has methods for shuffling, dealing,
// and figuring out how many cards are left in a deck.  It assumes a standard
// 52 card deck with suits of hearts, diamonds, spades, and clubs and with
// cards numbered 1-9, ace, king, queen, jack.
//
interface CardsInterface
{

    void shuffle();
    // Precondition: None
    // Postcondition: Reshuffles the deck and resets the remaining of cards in the
    //                deck to 52.

    int deal();
    // Precondition: Number of remaining cards MUST BE AT LEAST ONE
    // Postcondition: Returns a single card from the deck, decrements number of
    //                remaining cards by one.  If no cards in the deck, the program
    //                will terminate.
    //
    //				  A card is represented by a 3 digit number.  The 100s digit
    //                represents the suit of the card:
    //					1xx - Hearts
    //                  2xx - Diamonds
    //                  3xx - Spades
    //					4xx - Clubs
    //
    //                The tens and ones digits represents the face of the card:
    //					x01 - ACE
    //					x02 - 2
    //					x03 - 3
    //					x04 - 4
    //					x05 - 5
    //					x06 - 6
    //					x07 - 7
    //					x08 - 8
    //					x09 - 9
    //					x10 - 10
    //					x11 - Jack
    //					x12 - Queen
    //					x13 - King
    //

    int remaining();
    // Precondition: None
    // Postcondition: Returns number of remaining cards.
};


//
// Class Implementation
//
public class Cards
{
    private int deck[] = new int[53];
    private int card;
    
    Cards()
    {
        for (int i = 1; i <= 13; i++)
        {
                deck [i] = 100+i;
                deck[i+13] = 200+i;
                deck[i + 26] = 300+i;
                deck[i + 39 ] = 400+i;
        }
        card = 0;
    }

    public void shuffle()
    {
            for (int i = 1; i <= 52; i++)
            {
                    int rn = (int)(Math.random() * 52) + 1; 
                    int temp = deck[i];
                    deck[i] = deck[rn];
                    deck[rn] = temp;
            }
            card = 0;
    }

    public int deal()
    {
        int remain = remaining();
        int result = 0;
        if (remain == 0)
        {
            System.out.println("No Cards left. Reshuffle required");
            System.out.println("Program will terminate");
            result = -1;
            System.exit(0);
        }
        else
        {
            card ++;
            result = deck[card];
        }
        return result;
    }


    public int remaining()
    {
            int result = (52-card);
            return result;
    }
    
    public static void main(String[]args)
    {   
        Cards c = new Cards();
        for (int i = 1; i < 53; i++)
        {
            System.out.print(c.deck[i] + " ");
        }
        System.out.println();
        c.shuffle();
        for (int i = 1; i < 53; i++)
        {
            System.out.print(c.deck[i] + " ");
        }
        System.out.println("\nCard dealt: " + c.deal());
        System.out.println("Remaining cards: " + c.remaining());
    }
}

