Exercises: Complete the exercises using the Java files and then make note of the results in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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 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. 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. 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 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
Expert Answer:
Related Book For
Corporate Finance A Focused Approach
ISBN: 978-1439078082
4th Edition
Authors: Michael C. Ehrhardt, Eugene F. Brigham
Posted Date:
Students also viewed these programming questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
The 60-mm-diameter shaft rotates at 300 rev/min. This motion is caused by the unequal belt tensions on the pulley of 800 N and 450 N. Determine the power transmitted and the maximum shear stress...
-
Translate into dollars the balance sheet of North Carolina Leather Goods' German subsidiary. When North Carolina Leather Goods acquired the foreign subsidiary, a euro was worth $ 1.06. The current...
-
The following income statement and additional year - end information is provided. SONAD COMPANY Income Statement For Year Ended December 3 1 Sales $ 2 , 3 4 8 , 0 0 0 Cost of goods sold 1 , 1 5 0 , 5...
-
How can a paralegal assist a lawyer with the voir dire of the jury?
-
Enter the following column headings across the top of a sheet of paper: Enter the transaction letter in the first column and show the effect (if any) of each of the following transactions on each...
-
2. The following transactions apply to Mo's Auto Repair Service for the year 2020. 1) Issued stock to investors for $30,000 cash. 2) Purchased land for $24,000 cash. 3) Performed services on account...
-
Suppose there is a credit market imperfection due to limited commitment. As in the setup with collateralizable wealth we examined in this chapter, each consumer has a component of wealth which has...
-
(a) In Missouri, lowa, and some other part of the states, there are a lot of turbines that are eventually used to generate electricity. One particular turbine blade of radius 32 m rotates with a...
-
es Futura Company purchases the 67,000 starters that it installs in its standard line of farm tractors from a supplier for the price of $9.50 per unit. Due to a reduction in output, the company now...
-
What are the key principles and methodologies underpinning systemic organizational development approaches, and how do they facilitate holistic transformational change across interconnected facets of...
-
Global Marine obtained a charter from the state in January that authorized 1,000,000 shares of common stock, $5 par value. During the first year, the company earned $470,000 of net income and...
-
KnightWashing is a Canadian company that owns and operates a large automatic car wash facility near Montreal. The cost formula for its electricity cost is $1,200 per month plus $0.15 per car washed....
-
What factors contribute to the emergence, success, and decline of social movements, and how do they influence societal change ?
-
a. Explain enterprise systems and give three examples ofenterprise systems b. Explain Enterprise Resource Planning c. State 3 significance and benefits of ERP software andsystems
-
Tiger, Inc. signed a lease for equipment on July 1, 2007.The lease is for 10 years (the useful life of the asset).The first of 10 equal annual payments of $500,000 was made on July 1, 2007.The...
-
Garlington Technologies Inc.'s 2010 financial statements are shown below: Balance Sheet as of December 31, 2010 Suppose that in 2011 sales increase by 10% over 2010 sales and that 2011 dividends will...
-
(1) Why is the T-bills return independent of the state of the economy? Do T-bills promise a completely risk-free return? (2) Why are Alta Industriess returns expected to move with the economy whereas...
-
Calculate the firms cash conversion cycle given that annual sales are $660,000 and cost of goods sold represents 90% of sales. Assume a 365-day year.
-
Low1 Ltd is a wholly-owned subsidiary of Highl Ltd. Both companies are UK resident and prepare accounts to 31 March each year. Results for the year to 31 March 2024 are: Show how the trading loss...
-
A company which has seven wholly-owned subsidiaries has taxable total profits of 140,000 for the year to 31 March 2024. Dividends received in the year were 50,000. Calculate the corporation tax...
-
S Ltd has taxable total profits of 12,000 for the six months to 30 September 2023 and has no dividends received. Until 1 July 2023 the company had no associated companies but, on that date, its...
Study smarter with the SolutionInn App