On 12/16/2012 7:38 AM,
wrote:
> I'm trying to figure out the best way to layout a java program.
> Should I put each object into its own .java file? If I'm making a
> card game, that would be 52 .java files. Is that crazy? Normal?
What Arne and Robert said. In this case you want a single class with
two fields, one for suit and one for face value. (You could encode both
the suit and the value in to a single field. However this sort of space
saving is usually counter-productive, unless you're absolutely sure it's
needed.)
public class PlayingCard {
private final int value; // Ace = 1
private final Suit suit;
public static enum Suit { HEARTS, CLUBS, SPADES, DIAMONDS }
... ect....
}
You will of course have to make 52 instances of that class. Do that at
runtime, don't try to make 52 files.