Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Help with Deck of cards assignment and getting it to deal... Date: Sun, 03 Aug 2014 13:25:21 -0400 Organization: A noiseless patient Spider Lines: 119 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 3 Aug 2014 17:25:24 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="1975"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g5TFnKE0J0oOUsjAT3BQoYRMQl/oiWwc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.6.0 In-Reply-To: Cancel-Lock: sha1:0yUMg5vhnCjZY8NOyvbE3cKB0wk= Xref: csiph.com comp.lang.java.programmer:29521 On 08/03/2014 11:41 AM, Eric Sosman wrote: > On 8/3/2014 11:08 AM, Jeff Higgins wrote: >> On 08/01/2014 09:16 PM, Scott Dunning wrote: >>> Hello, I have an assignment for my summer class. FYI, I'm super new to >>> programming in general and this is my first time with java and it's a >>> summer class so it's going super fast (please be nice!) lol. >> >> No. It seems to be going slowly. The last three assignments you've >> brought here are rehashes. Surely by now you should have gone into >> interfaces and collections. >> >> Your Card class will be more easily used if it implement the >> java.lang.Comparable interface > > I'd advise against this, > because the ordering depends not on the > Card, but on the rules of whatever game is being played. Exactly. > There are > games where Ace is high, games where it is low, games where it can > be either at the discretion of the player, and for all I know there > may be games where Ace can lie between King and Deuce. And then > there's the question of suit: How does the Seven of Hearts compare > to the Jack of Clubs? Would knowing whether Hearts are trumps affect > your answer? > > Scott: Don't Go There; you'll just get lost. > Scott: If you don't go there you'll never find your way. package scratch; /** * The face value of a {@link Card}. * * Rank specifies one of 13 distinct, * implementation defined values and their order. * * The default values and order for Rank are: * Ace, Two through Ten inclusive, Jack, Queen, King. * * @author jeff * */ public interface Rank extends Comparable { } package scratch; /** * The suit of a {@link Card}. * * Suit specifies one of an implementation defined * number of distinct values and their order(if any). * * The default values and their order(highest to lowest) * for Suit are: Spades, Hearts, Diamonds, Clubs. * * @author jeff * */ public interface Suit extends Comparable { } package scratch; /** * A playing card. * * @author jeff * */ public interface Card extends Comparable { /** * Returns one of the 13 distinct values represented * in the implementation of the {@link Rank} interface. * * @return the Rank of this Card. */ Rank getRank(); /** * Returns one of the distinct values represented * in the implementation of the {@link Suit} interface. * * @return the Suit of this Card. */ Suit getSuit(); } package scratch; /** * An ordered set of playing {@link Card}s. * * @author jeff * */ public interface Deck extends Iterable { } Implement the Rank and Suit interfaces using the default values as immutable concrete classes. Implement an immutable Card interface using your concrete Rank and Suit classes. Implement the Deck interface, including its java.lang.Iterator implementation, as an immutable concrete class. Design and implement a Game class using the above implemented classes. The game is to deal a hand of five Cards from the Deck and compare hands until no further hands may be dealt.