Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 3: create a blueprint class for the dealer The Player class that you wrote for Task 2 serves as a blueprint for the human

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Task 3: create a blueprint class for the dealer The Player class that you wrote for Task 2 serves as a blueprint for the human player in the game (the user). The dealer is also a player in the game, but the dealer's behavior is different in several respects than the behavior of the user. In this task, you will write a class named Dealer that serves as a blueprint for an object that represents the dealer in the game. Save it your ps4 folder, and import the java.util package at the start of the file. Much of the state and behavior needed for a Dealer object is already present in the Player class. Thus, you should make Dealer a subclass of P7ayer, so that it will inherit the fields and methods of the Player class. In addition to the inherited fields and methods, this class will need: 1. a field of type boolean that indicates whether or not the dealer's first card should be revealed when the hand is printed. Make sure that the field is properly encapsulated. 2. its own constructor, which takes no parameters. It should call the constructor of the superclass to do the work of initializing the inherited fields, passing it the string "dealer" as the name of the player. In addition, it should initialize the boolean field to reflect the fact that the dealer's first card should not be revealed at the start of a given round of the game. 3. a mutator method called revea1Firstcard that takes no parameters and changes the value of the called object's boolean field to indicate that the dealer's first card should now be revealed. Note that this method will not actually print any cards on its own. Rather, by changing the value of the boolean field, it will cause subsequent calls to the printthand method to reveal the first card. 4. a printHand method that overrides the inherited version of that method. This version of the method should consult the called object's boolean field to determine what to do: - If the boolean field indicates that the first card should not be revealed, then it should display the String " XX " in place of the first card's usual string. In addition, it should not print the value of the hand. For example, here is one possible output of this method when the first card is hidden: XX8C - If the boolean field indicates that the first card should be displayed, then this method should produce the same output as the superclass version of the method. This method - like all subclass methods - does not have direct access to the fields inherited from the superclass. For example, it cannot directly access the array of cards. Instead, it should make use of the appropriate accessor methods as needed (e.g., to get the cards that it needs to print). 5. a wantsHit method that overrides the inherited version of that method. This version of the method should determine if the dealer should give herself another hit, and return true or false accordingly. See the section above entitled "Rules of the game" to see when the dealer should take another hit and when she should hold. Note that this method will ignore the first parameter of the method (the Scanner object), but it will use 5. a wantsHit method that overrides the inherited version of that method. This version of the method should determine if the dealer should give herself another hit, and return true or false accordingly. See the section above entitled "Rules of the game" to see when the dealer should take another hit and when she should hold. Note that this method will ignore the first parameter of the method (the scanner object), but it will use the second parameter of the method to obtain the necessary information about the opponent's hand. 6. a discardcards method that overrides the inherited version of that method. This version of the method should have the same effect as the inherited version of the method. In addition, it should reset the called object's boolean field to its original value, so that the first card in the dealer's next hand will not be revealed when the hand is first printed. - Modify the line in the main method that creates an object for the dealer (assigning it to the variable dealer). Instead of assigning a player object to that variable, you should assign an instance of your new subclass. The modified line should look like this: www.cs.bu.edu/courses/cs 112/ problem_sets/ps 4.html /2012:17 Problem Set 4 - CS 112, Boston University Player dealer = new Dealer () ; Note that you should not change the declared type of the variable, because doing so would cause some of the other B 7 ackjack code to break. Polymorphism allows us to assign an object of type Dealer to a variable of type Player, because Dealer is a subclass of P7ayer. - Uncomment the line in the playRound method that calls the revealfirstcard method. You should not make any other changes to the Blackjack class except the change described below in Task 4. If you have implemented everything correctly, the dealer's first card and value should be hidden during the user's turn, and the dealer should decide on its own hits, rather than asking you to make its decisions for it. Task 4: Implement the printresu7t method In B7ackjack.java, implement the printresu7t method so that it prints an appropriate message summarizing the results of a given hand. Here are some special points to keep in mind when writing this method: - If the user goes over 21 , they lose the game, regardless of the contents of the dealer's hand. - If the user gets 21 from their first two cards, a special "Blackjack!" message should be displayed unless the dealer also has Blackjack (in which case it is a push). - If the user and dealer both end up with the same value less than or equal to 21 , the message "Push!" should be displayed to indicate a tie. - If the user did not go over 21 and the dealer did go over, the user wins the game. - Otherwise, the decision about who won should be based on which player has the hand with higher value. See the sample runs above for what the result messages should look like. Note that the user's name is included in several of the messages. Once all of these tasks are completed, you should have a working Blackjack game! Testing your code To get repeatable hands for testing purposes, you can specify a seed for the randomnumber generator used by the Deck class when it shuffles the deck. Here is one way to do so

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions

Question

What steps should be taken to address any undesirable phenomena?

Answered: 1 week ago