In this lab, we will use the Java collections framework to write classes that represent collections...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this lab, we will use the Java collections framework to write classes that represent collections of playing cards from a standard 52-card deck. Additionally, we will use enumeration types to represent the ranks and suits of the cards. Below is a UML diagram with the details. enumeration"> Rank TWO("2") THREE ("3") FOUR("4") FIVE("5") SIX("6") SEVEN("7") EIGHT("8") NINE ("9") TEN("10") JACK("J") QUEEN("Q") KING("K") ACE ("A") -symbol: String -Rank (symbol: String) +toString(): String) -cards: List +Deck() +size(): int Deck interface Comparable +compareTo(o: T): int -rank: Rank -suit: Suit 1 Card +Card(Rank rank, Suit suit) +compareTo(Card card): int +equals(Object obj): boolean +getRank (): Rank +getSuit(): Suit +hashCode (): int +toString(): String +toString(): String +draw(): Card +draw(int count): List +shuffle(): void +getCardsByRank (Rank rank): List enumeration>> Suit CLUBS("C") DIAMONDS ("D") HEARTS("H") SPADES ("S") -symbol: String -Suit (symbol: String) +toString(): String BlackjackHand -CARD VALUES: Map -MAX VALUE = 21: int -cards = new ArrayList(): List -value = 8: int -numAcesAs11 = 0: int +BlackjackHand (Card c1, Card c2) +addCard(Card card): void +size(): int +getCardValues(): Map +getCards (): List +getValue(): int +toString(): String Before starting this assignment, you may want to review the following material: zyBook: 15.3, 15.5, and 15.6 Oracle Java Tutorial: Enum Types Rank and Suit Rank and Suit are enumeration types that represent the ranks and suits of a standard deck of playing cards. tostring(): Return the string representation of the enum constant, which is assigned to the symbol field. Card Card represents the cards in a standard deck. Each Card object has a Rank and a Suit. Card (Rank rank, Suit suit): Assign the given enum constants to the fields. If either reference is null, throw a NullPointerException. compareTo() : Implement the method so that a list of Cards is sorted first by Suit and then by Rank. (Hint: Java enums implement the Comparable interface, and the compiler automatically generates their compare To method.) equals (Object obj): Override the Object equals method so that two Cards are considered equal if they have the same Rank and Suit. Do this by following these steps: i. Check if the given object is an instance of Card. If not, return false. ii. Downcast the Object reference to Card. iii. Compare the Ranks and Suits of the Cards. Deck hashCode(): Any class that overrides equals should also override hashCode. Do this using a method of the Objects class as shown in the JUnit tests. toString(): Return the concatenation of the string representations of the Rank and Suit. Deck represents a standard deck of playing cards. Each Deck object has a List of Cards. Deck(): Initialize the List so that it contains all 52 unique Cards in sorted order. (Hint: Use the enum values() method, which is automatically added to Rank and Suit by the compiler.) draw(): Remove and return the first Card in the List. If the List is empty, return null. draw(int count) : Remove and return the given number of Cards from the front of the List. If the number is larger than the size, remove and return all the Cards. If the number is less than zero, return an empty List. shuffle(): Randomize the order of the Cards in the List. (Hint: Use a method of the Collections class.) size(): Return the number of Cards in the List. toString(): Return the string representation of the List. (Hint: List implementations include a tostring() method that returns a string representation of the list.) get Cards By Rank (Rank rank) : Return the list of cards in the deck, with the corresponding argument rank. BlackjackHand BlackjackHand represents a hand of cards in a game of Blackjack. Objects of the class are created with two Cards that are stored in a List. More Cards can be added until the value of the hand reaches 21 or greater. CARD_VALUES : A static Map from card ranks to card values. Cards with a numerical rank have the same value as the number; jacks, queens, and kings have a value of 10. Aces have a value of either 1 or 11, but a Map can only store one value with each key, so store the larger value. To initialize a static field like this that requires multiple lines of code, create the Map in a static initialization block. addCard (Card card): First, check if the card is null, throw a NullPointerException. If the current value of the hand is less than MAX_VALUE, add the given Card to the end of the List. Make sure you update numAcesAs11 if the card rank is Ace. Also, you must update the value field whenever you add a card. getCardValues(): Return a copy of the card values Map. getCards(): Return a copy of the cards List. getValue(): Return the value of the hand (i.e., the total value of all the Cards). While the value is greater than MAX_VALUE and the hand contains aces, choose the smaller value (i.e., 1) for Aces to minimize the total value. size(): Return the number of Cards in the List. toString(): Return the string representation of the List. In this lab, we will use the Java collections framework to write classes that represent collections of playing cards from a standard 52-card deck. Additionally, we will use enumeration types to represent the ranks and suits of the cards. Below is a UML diagram with the details. enumeration"> Rank TWO("2") THREE ("3") FOUR("4") FIVE("5") SIX("6") SEVEN("7") EIGHT("8") NINE ("9") TEN("10") JACK("J") QUEEN("Q") KING("K") ACE ("A") -symbol: String -Rank (symbol: String) +toString(): String) -cards: List +Deck() +size(): int Deck interface Comparable +compareTo(o: T): int -rank: Rank -suit: Suit 1 Card +Card(Rank rank, Suit suit) +compareTo(Card card): int +equals(Object obj): boolean +getRank (): Rank +getSuit(): Suit +hashCode (): int +toString(): String +toString(): String +draw(): Card +draw(int count): List +shuffle(): void +getCardsByRank (Rank rank): List enumeration>> Suit CLUBS("C") DIAMONDS ("D") HEARTS("H") SPADES ("S") -symbol: String -Suit (symbol: String) +toString(): String BlackjackHand -CARD VALUES: Map -MAX VALUE = 21: int -cards = new ArrayList(): List -value = 8: int -numAcesAs11 = 0: int +BlackjackHand (Card c1, Card c2) +addCard(Card card): void +size(): int +getCardValues(): Map +getCards (): List +getValue(): int +toString(): String Before starting this assignment, you may want to review the following material: zyBook: 15.3, 15.5, and 15.6 Oracle Java Tutorial: Enum Types Rank and Suit Rank and Suit are enumeration types that represent the ranks and suits of a standard deck of playing cards. tostring(): Return the string representation of the enum constant, which is assigned to the symbol field. Card Card represents the cards in a standard deck. Each Card object has a Rank and a Suit. Card (Rank rank, Suit suit): Assign the given enum constants to the fields. If either reference is null, throw a NullPointerException. compareTo() : Implement the method so that a list of Cards is sorted first by Suit and then by Rank. (Hint: Java enums implement the Comparable interface, and the compiler automatically generates their compare To method.) equals (Object obj): Override the Object equals method so that two Cards are considered equal if they have the same Rank and Suit. Do this by following these steps: i. Check if the given object is an instance of Card. If not, return false. ii. Downcast the Object reference to Card. iii. Compare the Ranks and Suits of the Cards. Deck hashCode(): Any class that overrides equals should also override hashCode. Do this using a method of the Objects class as shown in the JUnit tests. toString(): Return the concatenation of the string representations of the Rank and Suit. Deck represents a standard deck of playing cards. Each Deck object has a List of Cards. Deck(): Initialize the List so that it contains all 52 unique Cards in sorted order. (Hint: Use the enum values() method, which is automatically added to Rank and Suit by the compiler.) draw(): Remove and return the first Card in the List. If the List is empty, return null. draw(int count) : Remove and return the given number of Cards from the front of the List. If the number is larger than the size, remove and return all the Cards. If the number is less than zero, return an empty List. shuffle(): Randomize the order of the Cards in the List. (Hint: Use a method of the Collections class.) size(): Return the number of Cards in the List. toString(): Return the string representation of the List. (Hint: List implementations include a tostring() method that returns a string representation of the list.) get Cards By Rank (Rank rank) : Return the list of cards in the deck, with the corresponding argument rank. BlackjackHand BlackjackHand represents a hand of cards in a game of Blackjack. Objects of the class are created with two Cards that are stored in a List. More Cards can be added until the value of the hand reaches 21 or greater. CARD_VALUES : A static Map from card ranks to card values. Cards with a numerical rank have the same value as the number; jacks, queens, and kings have a value of 10. Aces have a value of either 1 or 11, but a Map can only store one value with each key, so store the larger value. To initialize a static field like this that requires multiple lines of code, create the Map in a static initialization block. addCard (Card card): First, check if the card is null, throw a NullPointerException. If the current value of the hand is less than MAX_VALUE, add the given Card to the end of the List. Make sure you update numAcesAs11 if the card rank is Ace. Also, you must update the value field whenever you add a card. getCardValues(): Return a copy of the card values Map. getCards(): Return a copy of the cards List. getValue(): Return the value of the hand (i.e., the total value of all the Cards). While the value is greater than MAX_VALUE and the hand contains aces, choose the smaller value (i.e., 1) for Aces to minimize the total value. size(): Return the number of Cards in the List. toString(): Return the string representation of the List.
Expert Answer:
Answer rating: 100% (QA)
public enum Suit CLUBSC DIAMONDSD HEARTSH SPADESS private String symbol private SuitStri... View the full answer
Related Book For
Elementary Statistics Picturing The World
ISBN: 9780321911216
6th Edition
Authors: Ron Larson, Betsy Farber
Posted Date:
Students also viewed these programming questions
-
You will have three separate, or internal classes that will: Instantiate a Card Instantiate a Deck of those Cards, and shuffle and deal them. Play the game. In this project you will simulate the...
-
This question concerns lexical grammars. (a) Tree Adjoining Grammars contain two types of elementary tree. (i) What are these trees called? [1 mark] (ii) If one were building a grammar for English...
-
Consider two farmers, A and B, produce farm products and sell in the same market. Assume that the supply of the two farmers products are the same but the demand for Farmer Bs product is relatively...
-
A particular security's default problems risk premium is 2 percent. For all securities, the inflation risk premium is 1.75 percent and the real risk-free rate is 3.5 percent. The security's liquidity...
-
A Peltier generator is made up of two thermoelectric elements connected in series (Fig. 11.13). One side of the Peltier generator is maintained at temperature T+ and the other temperature T. The...
-
In August 2014, Superior Structures of Ohio, LLC, and its president, Ryan Villhauer, applied for credit with Willoughby Supply Company, Inc. The application contained a section providing for a...
-
Capital budget methods, no income taxes Riverbend Company runs hardware stores in a tristate area. Riverbends management estimates that if it invests $250,000 in a new computer system, it can save...
-
The figure depicts Jack - in - the - box: "Jack" is attached inside a box by a spring, as shown. You estimate Jack's mass to be 0 . 4 k g . As so often happens, a sign tells you the spring constant:...
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
Mountain mechanical is considering a credit policy change that is expected to increase sales from $1,400,000 to $1,484,000 (6% increase). Bad debt losses are expected to go down from 4.0% to 3.5% as...
-
What is the Chart of Accounts?
-
update below code (Currency conversion program) to add loop. (Implement if/else ladder for menu control) Please tell me how to add loop(while) into the code 1) If the user enters an invalid input the...
-
The preliminary cost for a 41,000 ft 2 aircraft hangar must be estimated. The budget limit came in at $4.3 million. Perform two analyses: determine the maximum allowed size to be within budget at the...
-
If the economy booms, the Wildcat Company stock will have a return of 23.4 percent. If the economy goes into a recession, the stock will have a loss of 14.2 percent. The probability of a boom is 65...
-
Why is the production possibility frontier (curve) concave in shape (bows outward)?
-
On January 1, 2011, Praxis Corp. purchased 75.00% of the net assets of Sanchez Corp. for $178,945. The fair value of Sanchez Corp. on January 1, 2011, is estimated to be $238,594. The write-up of the...
-
Find the volume of the described solid S. A frustum of a right circular cone with height h, lower base radius R, and top radius r -r- --R
-
The probability that a particular rotator cuff surgery is successful is 0.9. 1. Find the probability that three rotator cuff surgeries are successful. 2. Find the probability that none of the three...
-
Use the data in Try It Yourself 1 to construct a 95% confidence interval for the mean number of hours worked by grocery store employees. Compare your result with the interval found in Example 3. a....
-
Refer to the data in Exercise 11. At = 0.10, perform a Scheff Test to determine which means have a significant difference. In Exercise 11 If the null hypothesis is rejected in a one-way ANOVA test...
-
If price moves from disequilibrium to equilibrium, what happens to the combination of producer and consumer surplus in the market?
-
Why does nearly every purchase you make provide you with consumer surplus?
-
The chapter frames the issue of the effects of taxation in terms of its effects on producer and consumer surplus. a. What does that framework leave out of the analysis? b. How might one frame the...
Study smarter with the SolutionInn App