Question: Exercises: Complete the exercises using the Java files and then make note of the results in the 10.08 Worksheet. 1. Complete the implementation of



Exercises: Complete the exercises using the Java files and then make note of the results in the 10.08 Worksheet. 1. Complete the implementation of the provided Card class. You will need to complete: a. a constructor that takes two String parameters that represent the card's rank and suit, and an int parameter that represents the point value of the card b. accessor methods for the card's rank, suit, and point value c. the matches method to test equality between two card objects d. the toString method to create a String that contains the rank, suit, and point value of the card object. The string should be in the following format: rank of suit (point value = pointValue) 2. Once you have completed the Card class, finish setting up the CardTester.java. Create three Card objects and test each method for each Card object. A sample of the expected output is shown below. Your cards and results may differ. BlueJ: Terminal Window - ... Options **** six of hearts Tests **** rank: 6 suit: hearts pointValue: 6 toString: 6 of hearts (point value = 6) **** matches Tests **** matching: true not matching: false X Exercises: Complete the exercises using the Java files and then make note of the results in the 10.08 Worksheet. 1. Complete the implementation of the Deck class by coding each of the following: a. Deck constructor-This constructor receives three arrays as parameters. The arrays contain the ranks, suits, and point values for each card in the deck. The constructor creates an ArrayList. Then creates the specified cards and adds them to the list. For example, if the parameters are ranks {"A", "B", "C"}, suits {"Giraffes", "Lions"}, and values would create the following cards: ["A", "Giraffes", 2], ["B", "Giraffes", 1], ["C", "Giraffes", 6], = = {2,1, 6}, the constructor ["A", "Lions", 2], ["B", "Lions", 1], ["C", "Lions", 6] and would add each of them to the ArrayList cards. The instance variable size would then be set to the size of cards, which in this example is 6. Finally, the constructor should shuffle the deck by calling the shuffle method. Note that you will not be implementing the shuffle method until Activity 4. C. size-This method returns the number of cards in the deck that are left to be dealt. b. isEmpty-This method should return true when the size of the deck is 0; false otherwise. d. deal-This method "deals" a card by removing a card from the deck and returning it, if there are any cards in the deck left to be dealt. It returns null if the deck is empty. There are several ways of accomplishing this task. Here are two possible algorithms: Algorithm 1: Because the cards are being held in an ArrayList, it would be easy to simply call the List method that removes an object at a specified index, and return that object. Removing the object from the end of the list would be more efficient than removing it from the beginning of the list. Note that the use of this algorithm also requires a separate "discard" list to keep track of the dealt cards. This is necessary so that the dealt cards can be reshuffled and dealt again. Algorithm 2: It would be more efficient to leave the cards in the list. Instead of removing the card, simply decrement the size instance variable and then return the card at size. In this algorithm, the size instance variable does double duty; it determines which card to "deal" and it also represents how many cards in the deck are left to be dealt. This is the algorithm that you should implement. 2. Once you have completed the Deck class, complete the DeckTester.java class. Add code in the main method to create a Deck with at least 10 cards and test each method for a Deck object. A sample of expected output is shown below. The exact values for cards and a deck will differ based on your choices. BlueJ: Terminal Window - Activity... Options **** Original Deck Methods **** toString: = 6 size Undealt cards: 13), king of red (point value = 13), king of blue (point value = queen of red (point value = 12), queen of blue (point value = 12), jack of red (point value = 11), jack of blue (point value = 11) Dealt cards: isEmpty: false size: 6 **** Deal a Card **** deal: king of red (point value = 13) X
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
