Next: Make a deck
Up: Assignment 10: Cards and
Previous: The Card class
- 1.
- Write a static (or class) method called compareCards that
takes two cards as arguments and returns an integer with value -1 if
the first card outranks the second, 1 if the second outranks the
first, and 0 if the two cards are the same. One card outranks another
if its rank is higher or, if the two ranks are the same, if its suit
is higher. The ranks are basically in numerical order, except that
Ace is the highest rank instead of the lowest. The order of the suits
is the order they appear in in the arrays above (Spades > Hearts >
Diamonds > Clubs).
- 2.
- Invoke your method from main and test that it works.
- 3.
- Write a second method called compare that is functionally
identical to compareCards except that it should be an instance
method that compares the current object (this) to a second card
that is passed as an argument.
- 4.
- Invoke this method from main, too.
Allen B. Downey
4/21/1998