92.3k views
5 votes
1. Download the cardGamesEclipseProject.zip file from the course website.

2. Import the project into Eclipse.
3. Modify the Card class:
(a) write the methods getSuitAsString and getValueAsString. These methods return a string representation of the suit and value respectively. For e.g. a heart can be returned as "H" and a spade can be returned as "S". For values, a value of 1 can return as "A", an 11 as "J' etc."
(b) modify the toString to return a neat String representation of the Card. E.g. an Ace of spades should be returned as "S A" and a 2 of clubs will be "C 2 ".
(c) to include a field private boolean isFaceUp that keeps track of whether the card is facing up or down.
(d) to include a method public void flip() that changes the card from face up to face down and vice versa.
4. Complete the class Hand as specified in the class.

User Jim Mack
by
7.2k points

1 Answer

4 votes

Final answer:

To handle the task, create the methods getSuitAsString and getValueAsString for string representations of the card's suit and value, override toString for a neat string output, and add a private field isFaceUp .

Step-by-step explanation:

Creating the Card Class in Eclipse

To modify the Card class as requested, you will first need to create two methods, getSuitAsString and getValueAsString. Each method should return the appropriate string representation of the suit and the value of the card, respectively. For example, hearts would return "H" and a value of 1 would return "A" for Ace. Jacks, Queens, and Kings would return "J", "Q", and "K" respectively.

Overriding the toString Method

The toString method should be overridden to provide a clear String representation of the Card object. It should concatenate the suit string and the value string, with a space in between. For example, an Ace of Spades would be represented as "S A".

Adding isFaceUp Field and flip Method

You'll also need to add a private boolean field named isFaceUp to keep track of the card's orientation (face up or face down). Furthermore, a method called flip should be implemented to change the card's orientation from face up to face down or vice versa when it is called.

Completing the Hand Class

Finally, ensure you complete the class Hand as detailed in the class specification provided. This may involve constructing a collection of Card objects and managing the various operations that can be performed on the hand, such as adding or removing cards.

User Tehlexx
by
8.2k points