Question: ***BASIC JAVA CODE. No complex code. No recursion. In this exercise, youll be creating two data types. It is up to you to determine whether

***BASIC JAVA CODE. No complex code. No recursion.

In this exercise, youll be creating two data types. It is up to you to determine whether the methods in each class should be static or not.

Create a new data type Card:

Every Card has a suit (String) and a rank (int). These should be private fields. Add a public constructor that creates a card given a String and an int. Add public get methods for both fields. Add a toString method that returns a String containing information about the card. These are examples of strings this method might return: "5 of Spades", "Ace of Hearts", "King of Clubs". Add a method called getHighCard() which takes an array of cards as input and returns the one with the highest value. Note that an Ace has a higher value than a King, which has higher value than a Queen, and so on. When the rank is the same, the values are assigned based on the suit: clubs (lowest), followed by diamonds, hearts, and spades (highest).

Create a second data type Deck: Every deck has an array of Cards Add a public constructor that takes no inputs and initializes the array of cards with the usual 13 cards per suit (from Ace to King). Add a method called shuffle() which shuffles the deck. Add a method called deal() which takes as input an integer and returns an array with the given number of cards taken from the top of the deck. After the method executes, the card dealt should not be part of the deck anymore!

Finally in the main method of a class called PlayCards, create a deck, shuffle it, deal a hand with five cards, select the highest card, and display it.

In your presentation make sure to include the following: Answer the following questions: How did you decide to represent Aces, Jacks, Queens, and Kings? Is Card a mutable or an immutable data type? Were you able to write the constructor of the Deck class using only one loop? How did you decide to represent the top of the deck and why? Show your code for getHighCard() and deal(). Run the class PlayCards and demonstrate how it works.

***BASIC JAVA CODE. No complex code. No recursion. In this exercise, youll

In this exercise you'll be creating two data types. It is up to you to determine whether the methods in each class should be static or not. Create a new data type Card: Every Card has a suit (String) and a rank (int). These should be private fields. Add a public constructor that creates a card given a String and an int. Add public get methods for both fields. Add a toString method that returns a String containing information about the card. These are examples of strings this method might return: "5 of Spades", "Ace of Hearts", "King of Clubs". (if you are working in a pair) Add a method called getHighcard() which takes an array of cards as input and returns the one with the highest value. Note that an Ace has a higher value than a King, which has higher value than a Queen, and so on. When the rank is the same, the values are assigned based on the suit: clubs (lowest), followed by diamonds, hearts, and spades (highest). Create a second data type Deck: Every deck has an array of Cards Add a public constructor that takes no inputs and initializes the array of cards with the usual 13 cards per suit (from Ace to King). (if you are working in a pair) Add a method called shuffle() which shuffles the deck. Add a method called deal() which takes as input an integer and returns an array with the given number of cards taken from the top of the deck. After the method executes, the card dealt should not be part of the deck anymore! Finally if you are working in a pair, in the main method of a class called PlayCards, create a deck, shuffle it, deal a hand with five cards, select the highest card, and display it. In your presentation make sure to include the following: Answer the following questions: - How did you decide to represent Aces, Jacks, Queens, and Kings? Is Card a mutable or an immutable data type? Were you able to write the constructor of the Deck class using only one loop? - How did you decide to represent the top of the deck and why? Show your code for getHighCard() and deal(). Run the class PlayCards and demonstrate how it works. Extra (not required for the presentation]: Assuming that you have access to a truly random number generator, think about how can you implement the method shuffle() so that each of the 52! permutations of the deck is equally likely

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!