// Arup Guha
// 11/17/2009
// Solution to AP Computer Science Class UnoCard (for Uno assignment)
// Edited on 12/12/2015 for Junior Knights.

import java.util.*;

public class UnoCard {

	final private static String[] colors = {"Yellow", "Red", "Green", "Blue"};

	private int color;
	private int number;

	// Creates a random Uno card where color is randomly assigned in the range [0,3] and
	// number is randomly assigned in the range [1, 9].
	public UnoCard(Random r) {
		color = r.nextInt(4);
		number = r.nextInt(9) + 1;
	}

	// Precondition: 0 <= c < 4, 1 <= n <= 9
	// Postcondition: Creates a UnoCard that is Yellow if c=0, Red if c=1,
	//                Green if c=2 and Blue if c=3 with the number n.
	public UnoCard(int c, int n) {
		color = c;
		number = n;
	}

	// Returns a String representation of a card. (Example: Yellow 5)
	public String toString() {
		return colors[color]+" "+number;
	}

	// Returns true iff you can play other on this card.
	public boolean canPlay(UnoCard other) {
		return this.color == other.color || this.number == other.number;
	}

	public static void main(String[] args) {

		Random r = new Random();

		// Create three cards to test both constructors.
		UnoCard first = new UnoCard(r);
		UnoCard second = new UnoCard(r);
		UnoCard third = new UnoCard(2,7);
		UnoCard fourth = new UnoCard(2,8);
		UnoCard fifth = new UnoCard(1,7);

		// Print out all three to test toString.
		System.out.println("Card 1: "+first);
		System.out.println("Card 2: "+second);
		System.out.println("Card 3: "+third);
		System.out.println("Card 4: "+fourth);
		System.out.println("Card 5: "+fifth);

		// And some canPlays.
		if (first.canPlay(second))
			System.out.println("Can play "+first+" on "+second);
		if (first.canPlay(third))
			System.out.println("Can play "+first+" on "+third);
		if (third.canPlay(second))
			System.out.println("Can play "+third+" on "+second);
		if (third.canPlay(fourth))
			System.out.println("Can play "+third+" on "+fourth);
		if (third.canPlay(fifth))
			System.out.println("Can play "+third+" on "+fifth);
		if (fifth.canPlay(fourth))
			System.out.println("Can play "+fifth+" on "+fourth);


	}

}
