/*
 * EnumTest.java
 *
 * Created on June 2, 2004, 3:03 PM
 */

//need this for the card example below
import java.awt.Color;
import java.util.ArrayList;
/**
 *
 * @author  cpresser
 */
public class EnumAdvanceTest {

    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //test of a more involved enumeration (CS2)

        //create and print a deck of cards
        ArrayList<Card> deck = new ArrayList<Card>();
        
	//use the enumeration with the foreach loop
        for(Suit suit: Suit.values()){
            //perhaps value was a bad choice of names
            for(CardValue value: CardValue.values()){
                //create a crad
                Card card = new Card(suit, value);
                //add it to the deck
                deck.add(card);
                //print out the card
                System.out.println(card);
            }
        }
    }
}

//create a class for a card. Normally structures such as those below
//would appear in seperate files.
class Card{
    //made these public members so to shorten the code
    public final Suit suit;
    public final CardValue value;
    
    //constructor for a card
    public Card(Suit s, CardValue v){
        this.suit = s;   
        this.value = v;
    }
    
    public String toString(){
        return value + " of " + suit;
    }
}

//card suits (normally this would be in another file like classes
// and interfaces)
enum Suit {
    CLUBS(Color.BLACK), DIAMONDS(Color.RED), 
    HEARTS(Color.RED), SPADES(Color.BLACK);
     
    //an instance variable to store the color
    private Color color;
    
    //constructor for values--can't be public
    Suit(Color color){
        //store the color
        this.color = color;
    }
   
    //an accessor method for the color
    public Color getColor(){
        return color;
    }    
}

enum CardValue {
    ACE(1, 1, 11), DEUCE(2, 2), THREE(3, 3), FOUR(4, 4), 
    FIVE(5, 5), SIX(6, 6), SEVEN(7, 7), EIGHT(8, 8), 
    NINE(9, 9), TEN(10, 10), JACK(11, 10), QUEEN(12, 10), KING(13, 10);
    
    //extra private information
    private int order;
    private int value;
    private int otherValue;
    
    //constructor
    CardValue(int order, int value){
        this.order = order;
        this.value = value;
        this.otherValue = -1;
    }
    
    //other constructor
    CardValue(int order, int value, int otherValue){
        this.order = order;
        this.value = value;
        this.otherValue = otherValue;
    }
    
    //accessor methods
    public int getOrder(){
        return order;
    }
    
    public int getValue(){
        return value;
    }
    
    public int getOtherValue(){
        return otherValue;
    }
    
    public boolean hasOtherValue(){
        return (otherValue >= 0);
    }
}