Writing your own classes in Java (implementing Card game)

Testing/demonstrating methods of the Card class:


public class Card {
        // to-do: this class needs comments!!!!	

	private String suit;
	private String value;	
	private int numericValue;
	
	
	public Card(String suit, String value) {
		this.suit = suit;
		this.value = value;
                // to-do: calculate numeric value and store it into 
                // this.numericValue

	}
	
	public String getSuit() {
		return this.suit;
	}
	
	public String getValue() {
		return this.value;
	}
	
	public int getNumericValue() {		
		return this.numericValue;
	}
		
	public String toString() {
		return null;
	}
	
	public int compareTo(Card other) {
		return 0;	// CHANGE THIS!!!!!
	}
/*
	public static void main(String[] args) {
		Card aceSpades = new Card("Spades", "A");
                // expect: Spades
		System.out.println(aceSpades.getSuit());
                // expect: A
		System.out.println(aceSpades.getValue());
                 // expect: 14              
		System.out.println(aceSpades.getNumericValue());
		
		Card fiveHearts = new Card("Hearts", "5");
                // expect: Hearts
		System.out.println(fiveHearts.getSuit());
                // expect: 5
		System.out.println(fiveHearts.getValue());
                // expect: 5
		System.out.println(fiveHearts.getNumericValue());
		
                //user-friendly printing of a card: implement toString
		System.out.println(aceSpades);
		System.out.println(fiveHearts);
                
		// this should cause the program to exit
		Card invalidValue = new Card("Hearts", "S");
		
		// Comparison of cards by value
                // expect: a value > 0
		System.out.println(aceSpades.compareTo(fiveHearts));
                // expect: a value < 0
		System.out.println(fiveHearts.compareTo(aceSpades));
                // expect: a value = 0
		System.out.println(aceSpades.compareTo(aceSpades));
		
	}
*/
}

CSci 2101 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.