Please need help with this problem 10. a. Playing cards are used in many compute
ID: 3635429 • Letter: P
Question
Please need help with this problem10. a. Playing cards are used in many computer games, including versions of such classics as Solitaire, Hearts, and Poker. Design a Card class that contains a string data field to hold a suit (spades, hearts, diamonds, or clubs) and a numeric data field for a value from 1 to 13. Include get and set methods for each field. Write an application that randomly selects two playing cards and displays their values.
b. Using two Card objects, design an application that plays a simple version of the card game War. Deal two Cards— one for the computer and one for the player. Determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is low. Make sure that the two Cards dealt are not the same Card. For example, a deck cannot contain more than one Queen of Spades.
Explanation / Answer
public class PlayingDeck { List deck = new ArrayList(); PlayingDeck() { //Instantiate and populate list with 52 card objects } public void addCard() { //Adds cards to the end of the ArrayList } public void removeCard() { //Removes cards from the beginning of the ArrayList } public int size() { //return the size } public void shuffle() { //Shuffle the deck } } public class ShreddedDeck { List deck = new ArrayList(); ShreddedDeck() { //Instantiated empty, no cards at start } public void addCard() { //Adds cards to the beginning of the ArrayList } public void removeCard() { //Removes cards from the end of the ArrayList }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.