Question: Program 2b: CardDeck in Java. Hello Chegg, I have been tyring to complete this lab for quite some time now but now I found myself
Program 2b: CardDeck in Java.
Hello Chegg,
I have been tyring to complete this lab for quite some time now but now I found myself sstuck and was wondering if I could get assistant to finsh this class. I also attached (the bottom) my own code, and I am hooping we could use it to finsh the rest.
Thank You so much! ( I always rate positively ) ..... :)
Rolling with the same theme, we are going to focus on the characteristics and functionality of a deck of cards. In this program you will be creating a "CardDeck.java" file in your IDEs that will have the following characteristics:
Class Variables:
public String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public String[] suits = {"Clubs", "Diamonds", "Hearts", "Spades"}; public String[] deck // initialize to size of 52 for the number of cards there are in a standard deck (NO JOKERS) These arrays will be important, and for that reason I want you to put the "ranks" and "suits" array in your code EXACTLY as you see it above. When we populate our deck we are going to store each card exactly as we say them, for example "Ace of Spades" or "3 of Clubs".
public CardDeck(), this will be your constructor for your class and will be where you fill your "deck" array. This one is going to be a bit tricky to populate but I know you guys can do it. I'm going to give you some hints to get started. For starters, use a for-loop within a for-loop, one for the ranks and one for the suits. Initialize the index tracker of the "deck" array OUTSIDE of these for-loops. Remember to store each card in "deck" as you say it: "rank" of "suit". I know this is going to be tricky but come by office hours of either the TAs or Professor Kraft we are going to be here to help you all.
public String getCard(int index), return the card at the given index.
public String getFirst(), return the first card in "deck".
public String getLast(), return the last card in "deck".
public String royalFlush(), return a String of cards that are contained in a Royal Flush poker hand. If you don't know what a Royal Flush consists of, you can give it a quick google search and you'll be able to figure it out. But the way I would like you to return it is all the cards on one line with a comma then a space in between each card.
public class CardDeck { public String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; public String[] suits = {"Clubs", "Diamonds", "Hearts", "Spades"}; private int deckNum = 52; public String[] deck = new String [deckNum]; public CardDeck () { for (int i = 0; i < ranks.length - 1; i++) { for (int j = 0; j < suits.length - 1; j++) { do (int t; t < deckNum; t++) { //area where I got stuck deck [i] = ranks [i] + suits [j]; } } } } public String getCard (int index) { return deck [index]; } public String getFirst () { return deck [1]; } public String getLast () { return deck [deckNum - 1]; } public String royalFlush () { }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
