169k views
5 votes
The next class to look at is the Card class. Here are some features: • We have a concept called an enumerator. This is an opportunity to make sense of something the computer has no concept of. In this case, the computer has no concept of the suits or card faces. To us, they have meaning, and we can use that meaning to create tests and other game logic. Consider what would be needed to play a card game where you need to say the 3 has a greater value than a 2. Now this may seem simple, but what about face cards? How does it fit in with aces?

How do you compare an ace and a 2? Let's look further down at the compareTo() function. What we are doing here is a bit more advanced but we have enough to understand the main code. Let's say we have two cards, thisCard (known as "this" or this instance) and otherCard. How could we make sense of an arbitrary sequence? I say it is arbitrary because we cannot simply match it to a typical binary numbering sequence. What if we simply look at the card value and give it a numeric value? This is what the cardFaceToNumber() function does. So take a look at how we can identify the card faces and return a number. It isn't important what number is returned as much as we are ranking them. It is the rankings that are then compared to say whether thisCard is greater than the otherCard, thisCard is less than the otherCard, or the two cards are equal. Notice we are implementing the Comparable interface. This may not mean much right now, but this is how we can later use a sort on the ArrayList and get our cards in a particular order. This is also the same interface used on letters to determine how to sequence letters. Deck Just like with the Dice, we have the plural form of card called Deck. It's a very simple class, but all concepts related to a set of cards would be housed here. Note a few features: • Notice how I can shuffle the cards by using a Deck function. This reduces the number of times I may need to implement this function in my code. • Notice there is a quick way of getting a standards deck of 52 cards by using embedded for loops. This takes advantage of the numerators as if they were lists and you can iterate over the lists. I have left an example of how to move a card from one deck to another. This is a great concept to understand since we can pull out objects from one place and place them in other places. Consider features of the code and discuss them as examples on this week's Q&A. Assignment Details The assignment submission is as follows: 1 eater App 1. Create ArrayLists for the Theater, Movies, and MovieShowing. 2. Using your menu, create the features for listing, adding, and removing from each of the three areas. 2. Smart Home App 1. Create ArrayLists for each of the kitchen items.
2. Using your menu, create features for listing, adding, and removing the kitchen smart devices.

User Adu
by
8.2k points

1 Answer

3 votes

Final answer:

The Card class is used to represent playing cards in a card game, while the Deck class is responsible for managing sets of cards.

Step-by-step explanation:

Card Class

The Card class is used to represent a playing card in a card game. It includes features such as an enumerator to make sense of the suits and card faces, a compareTo() function to compare the values of two cards, and the implementation of the Comparable interface to enable the sorting of cards. The Card class also plays a role in the creation of a Deck, which is a collection of cards used in a card game.

Deck Class

The Deck class is responsible for managing a set of cards. It includes features like shuffling the cards, creating a standard deck of 52 cards, and moving cards between decks. The Deck class is used to store the cards needed for a game, and it provides functionality to manipulate and interact with the cards.

User Bohica
by
8.3k points

Related questions

asked Oct 22, 2024 217k views
Agatha asked Oct 22, 2024
by Agatha
8.1k points
1 answer
5 votes
217k views
1 answer
2 votes
103k views