Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > proper use of .java files (layout)

Reply
Thread Tools

proper use of .java files (layout)

 
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 4:17 PM, markspace wrote:
> On 12/17/2012 10:28 AM, Lew wrote:
>> markspace wrote:
>>> public class PlayingCard {
>>>
>>> private final int value; // Ace = 1

>>
>> I would make this an enum.
>>
>> "Ace = 1" is not a valid association in the problem domain, and its use
>> as a representation creates risk of an artificial equivalency.

>
> I was actually thinking about that. I don't like the idea of trying to
> encode most of the values of a face card as enums.


Why not?

13 distinct values with an order but no numeric values
seems a perfect fit for enum to me.

> Another example: in many standard decks, the names of the suits are not
> Spades, Hearts, etc. but vary by country. Again I'm leaving that for
> some other part of the program. Localization of card names can be done
> by wrapping this PlayingCard with a GermanPlayingCard, for example.


Or by using standard I18N techniques in the UI layer!

Arne


 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 1:28 PM, Lew wrote:
> markspace wrote:
>> You will of course have to make 52 instances of that class. Do that at

>
> No "of course" about it.
> http://www.hoylegaming.com/rules/sho...spx?RuleID=209
>
>> runtime, don't try to make 52 files.

>
> How many cards in a blackjack shoe?
> http://en.wikipedia.org/wiki/Blackjack
>
> If you hard-code certain assumptions, e.g., that there are 52 cards in the deck,
> your program will be unable to model many games.


I would argue that a deck is always 52 cards, but that some
games use more than one deck.

Arne


 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 5:32 AM, lipska the kat wrote:
> Here is a possible outline for a simple card game component
> It has NOT been compiled.


And it will not.

.... is not valid Java (in the context where it is used).

> Comments welcome
>
> Card.java
>
> public class Card{
> //enumeration types for rank and suit perhaps
> ...
> }
>
> ==========================
>
> Deck.java
>
> public class Deck{
>
> private Card[] deck = null; //implementation hidden from clients
>
> public Deck(Integer cardCount){
> deck = new Card[cardCount]; //not all games use all the cards
> }
> ...
> }
>
> =========================
>
> Dealer.java
>
> public class Dealer{
>
> private Deck deck = null;
>
> public Dealer(Deck deck){
> this.deck = deck;
> }
>
> public void shuffle(){
> ... //delegate to deck ?
> }
> ...
>
> public List<Card[]> deal(Integer hands, Integer cardsPerHand){
> ...
> }
> }
>
> ===========================
>
> Snap.java
>
> public class Snap {
>
> private Deck deck = null;
> private Dealer dealer = null;
>
> public Snap(){
> this.deck = new Deck(54); // don't forget the jokers
> this.dealer = new Dealer(deck);
> }
>
> public void play(Integer numPlayers){
> dealer.shuffle();
> dealer.deal(numPlayers, 0); // 0 indicates deal all to players
> ...
> }
> ...
> }
>
> Java is well suited to an 'Object Oriented' approach to software design
> The above outline is just one of many possible OO solutions.



A Deck constructor with just the number of jokers would make
more sense to me.

The Deck(cardCount) does not specify what cards are there. And
it is not really a deck but a deck with something added or
removed.

Arne

 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-18-2012
On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajh°j <(E-Mail Removed)>
wrote:

[snip]

>13 distinct values with an order but no numeric values
>seems a perfect fit for enum to me.


An enum does not guarantee an order.

Do you play poker? Aces are usually high, but can be low in the
case of straights.

[snip]

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-18-2012
On Mon, 17 Dec 2012 20:58:59 -0500, Arne Vajh°j <(E-Mail Removed)>
wrote:

>On 12/17/2012 1:28 PM, Lew wrote:


[snip]

>> If you hard-code certain assumptions, e.g., that there are 52 cards in the deck,
>> your program will be unable to model many games.

>
>I would argue that a deck is always 52 cards, but that some
>games use more than one deck.


Some games do not use all of the deck; some include one or more
jokers. See the section "Modified Deck" in
http://boardgamegeek.com/wiki/page/S...ing_Card_Games
for several examples.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 8:58 PM, Arne Vajh°j wrote:
> On 12/17/2012 1:28 PM, Lew wrote:
>> markspace wrote:
>>> You will of course have to make 52 instances of that class. Do that at

>>
>> No "of course" about it.
>> http://www.hoylegaming.com/rules/sho...spx?RuleID=209
>>
>>> runtime, don't try to make 52 files.

>>
>> How many cards in a blackjack shoe?
>> http://en.wikipedia.org/wiki/Blackjack
>>
>> If you hard-code certain assumptions, e.g., that there are 52 cards in
>> the deck,
>> your program will be unable to model many games.

>
> I would argue that a deck is always 52 cards, but that some
> games use more than one deck.


How come a brand-new pack of cards always has fifty-four?

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 9:18 PM, Gene Wirchenko wrote:
> On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajh°j <(E-Mail Removed)>
> wrote:
>
> [snip]
>
>> 13 distinct values with an order but no numeric values
>> seems a perfect fit for enum to me.

>
> An enum does not guarantee an order.


In the Java I use enums have a compareTo method.

Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 9:25 PM, Eric Sosman wrote:
> On 12/17/2012 8:58 PM, Arne Vajh°j wrote:
>> On 12/17/2012 1:28 PM, Lew wrote:
>>> markspace wrote:
>>>> You will of course have to make 52 instances of that class. Do that at
>>>
>>> No "of course" about it.
>>> http://www.hoylegaming.com/rules/sho...spx?RuleID=209
>>>
>>>> runtime, don't try to make 52 files.
>>>
>>> How many cards in a blackjack shoe?
>>> http://en.wikipedia.org/wiki/Blackjack
>>>
>>> If you hard-code certain assumptions, e.g., that there are 52 cards in
>>> the deck,
>>> your program will be unable to model many games.

>>
>> I would argue that a deck is always 52 cards, but that some
>> games use more than one deck.

>
> How come a brand-new pack of cards always has fifty-four?


It does not always.

It comes with 2, 3 or maybe even 4 jokers.

So number of jokers should be a constructor argument, if
it has to be realistic.

Arne


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 9:29 PM, Arne Vajh°j wrote:
> On 12/17/2012 9:25 PM, Eric Sosman wrote:
>> On 12/17/2012 8:58 PM, Arne Vajh°j wrote:
>>>
>>> I would argue that a deck is always 52 cards, but that some
>>> games use more than one deck.

>>
>> How come a brand-new pack of cards always has fifty-four?

>
> It does not always.
>
> It comes with 2, 3 or maybe even 4 jokers.
>
> So number of jokers should be a constructor argument, if
> it has to be realistic.


Can we say, then, that "a deck is always 52 cards, for
suitable values of 52?"

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      12-18-2012
On 12/17/2012 9:32 PM, Eric Sosman wrote:
> On 12/17/2012 9:29 PM, Arne Vajh°j wrote:
>> On 12/17/2012 9:25 PM, Eric Sosman wrote:
>>> On 12/17/2012 8:58 PM, Arne Vajh°j wrote:
>>>>
>>>> I would argue that a deck is always 52 cards, but that some
>>>> games use more than one deck.
>>>
>>> How come a brand-new pack of cards always has fifty-four?

>>
>> It does not always.
>>
>> It comes with 2, 3 or maybe even 4 jokers.
>>
>> So number of jokers should be a constructor argument, if
>> it has to be realistic.

>
> Can we say, then, that "a deck is always 52 cards, for
> suitable values of 52?"


Very funny.

A deck is 52 + number of jokers cards.

A game may be multiple decks or maybe even a subset of a deck.

Arne


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the proper way to use SocketChannel.finishConnect()? - Java 1 07-26-2005 01:03 AM
Proper use of assertions Razvan Java 5 10-08-2004 02:39 PM
Proper way to use an imported constant under 'use strict'? H. Wade Minter Perl Misc 8 04-25-2004 12:58 AM
Proper (vs. desirable) use of Graphics object Wolfgang Java 7 01-23-2004 05:42 PM
Proper use of CharsetDecoder? Harald Kirsch Java 1 08-05-2003 07:15 PM



Advertisments