Objective The objective of this lab is for you to develop some classes for use in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Objective The objective of this lab is for you to develop some classes for use in card games. The classes you'll build are: Card: models a playing card. Deck: models a deck of 52 cards Hand: models the cards held by one player Incomplete implementations of these classes are posted in a zip file on Brightspace, along with three JUnit test classes (CardTest, DeckTest, and HandTest). Part 1 - Class Card An Anglo-American deck of playing cards contains 13 cards for each of four suits (hearts, diamonds, clubs and spades), for a total of 52 cards. Each of the 13 cards in a given suit has a unique rank (ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king). The objective of this part is to implement a Java class that models these playing cards. 1. Double-click the icon for class Card to open the incomplete implementation of the class in the BlueJ editor. Make sure you update the documentation at the beginning of the class (i.e., add your name as an author, and update the version number and date). Read the documentation for the constructor and methods. Notice that the fields are called suit and rank, and the constructor parameters have the same names. Type the following statements in the body of the the Card constructor (there shouldn't be any other statements in the constructor): rank = rank; suit = suit; Do you think the constructor will correctly initialize the newly created card? Compile Card. After the class compiles without errors, create a new Card object and place it on the object bench. Use the object inspector to examine the object's fields. Was your hypothesis correct? Did the constructor correctly initialize the Card object? 2. Edit the constructor body to look like this: this.rank = rank; this.suit = suit; Compile Card. Create a new Card object and place it on the object bench. Use the object inspector to examine the object's fields. Did the constructor correctly initialize the Card object? Is variable this.rank the field called rank or the parameter called rank? Is variable rank the field called rank or the parameter called rank? You can confirm your answer by reading Section 3.12.2. If a constructor or a method has a parameter with the same name as a field, how do we write statements that correctly use both variables? 3. Write the rank () and suit () methods. Be sure to add the "@return" javadoc statements. Don't write has SameRank () or is EqualTo () yet. 4. Compile unit test class CardTest. Run the test cases in CardTest (right-click on the CardTest icon and select Test All from the pop-up menu). testCreateAllCards should pass, but the other test cases will fail (you haven't written the methods that those test cases exercise). If necessary, modify your class until it passes testCreateAllCards. 5. Write has SameRank (). Don't forget the "@param" and "@return" java doc statements. Run all the tests in CardTest. testSameRank should now pass. 6. Write isEqual To (). Remember that you must use the "equals" method (not "==" to compare Strings). Don't forget the "@param" and "@return" java doc statements. Run all the tests in CardTest. testIsEqual To should now pass. 7. Generate the javadoc (from the BlueJ window, select Tools, then Project Documentation) and ensure that it is complete and correct. Part 2 Class Deck 1. Open the incomplete implementation of Deck in the BlueJ editor and read the documentation for the constructor and methods. Notice that this class has a single field called cards. The class must not define any additional fields - the fields called cards is sufficient. Of course, your constructor and methods may need to define one or more local variables. Don't litter your class with magic numbers. Several constants have been defined in this class - make sure you use them. Make sure you update the documentation at the beginning of the class (i.e., add your name as an author, and update the version number and date). 2. Write constructor Deck (), buildSuit (), isEmpty() and size (). Don't forget the javadoc comments (@param, @return). The constructor must call private method buildSuit () four times (once for each suit). Each time buildSuit () is called, 13 new cards will be added to the deck. The constructor does not shuffle the deck of cards. Compile the Deck class. After the class compiles without errors, compile DeckTest. Run the test cases in DeckTest. testCreate Deck should pass, but the other test cases will fail. 3. Write dealCard (). dealCard () should always remove and return the card at the front of the deck, i.e. the first card in the ArrayList. It should not randomly pick the card it will remove. Run all the tests in DeckTest. test Deal and testHas52Cards should now pass. If both tests fail, the problem is probably in your dealCard ( ) method. Iftest Deal passes but testHas52Cards fails, the problem is probably in your constructor or buildSuit () method (you're likely not initializing the deck with 52 different cards). Don't forget the javadoc comments (@param, @return). 4. Write shuffle (). The method should create one instance of java.util.Random() and repeatedly (at least 10,000 times) invoke nextInt (int n) to generate the positions of two cards in the deck to interchange. Run all the tests in DeckTest. testShuffle should now pass. Don't forget the javadoc comments (@param, @return). 5. Generate the javadoc and ensure that it is complete and correct. Part 3 - Class Hand 1. Open the incomplete implementation of Hand in the BlueJ editor and read the documentation for the constructor and methods. Complete the implementation of the class, including the javadoc comments. As you write each method, run the tests in HandTest to provide you with feedback. Notes: a. The class must not define any additional fields - the fields called cards is sufficient. Of course, your methods may need to define one or more local variables. b. Most of the methods in Hand will be very short; for the most part, they will simply call the appropriate method on the hand's ArrayList object. c. Notice that the String returned by toString () should have a single space between each number (card rank), and should have no leading or trailing spaces. 2. Generate the javadoc and check that it is complete and correct. Submission Submit Card.java, Deck.java, and Hand.java. Objective The objective of this lab is for you to develop some classes for use in card games. The classes you'll build are: Card: models a playing card. Deck: models a deck of 52 cards Hand: models the cards held by one player Incomplete implementations of these classes are posted in a zip file on Brightspace, along with three JUnit test classes (CardTest, DeckTest, and HandTest). Part 1 - Class Card An Anglo-American deck of playing cards contains 13 cards for each of four suits (hearts, diamonds, clubs and spades), for a total of 52 cards. Each of the 13 cards in a given suit has a unique rank (ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king). The objective of this part is to implement a Java class that models these playing cards. 1. Double-click the icon for class Card to open the incomplete implementation of the class in the BlueJ editor. Make sure you update the documentation at the beginning of the class (i.e., add your name as an author, and update the version number and date). Read the documentation for the constructor and methods. Notice that the fields are called suit and rank, and the constructor parameters have the same names. Type the following statements in the body of the the Card constructor (there shouldn't be any other statements in the constructor): rank = rank; suit = suit; Do you think the constructor will correctly initialize the newly created card? Compile Card. After the class compiles without errors, create a new Card object and place it on the object bench. Use the object inspector to examine the object's fields. Was your hypothesis correct? Did the constructor correctly initialize the Card object? 2. Edit the constructor body to look like this: this.rank = rank; this.suit = suit; Compile Card. Create a new Card object and place it on the object bench. Use the object inspector to examine the object's fields. Did the constructor correctly initialize the Card object? Is variable this.rank the field called rank or the parameter called rank? Is variable rank the field called rank or the parameter called rank? You can confirm your answer by reading Section 3.12.2. If a constructor or a method has a parameter with the same name as a field, how do we write statements that correctly use both variables? 3. Write the rank () and suit () methods. Be sure to add the "@return" javadoc statements. Don't write has SameRank () or is EqualTo () yet. 4. Compile unit test class CardTest. Run the test cases in CardTest (right-click on the CardTest icon and select Test All from the pop-up menu). testCreateAllCards should pass, but the other test cases will fail (you haven't written the methods that those test cases exercise). If necessary, modify your class until it passes testCreateAllCards. 5. Write has SameRank (). Don't forget the "@param" and "@return" java doc statements. Run all the tests in CardTest. testSameRank should now pass. 6. Write isEqual To (). Remember that you must use the "equals" method (not "==" to compare Strings). Don't forget the "@param" and "@return" java doc statements. Run all the tests in CardTest. testIsEqual To should now pass. 7. Generate the javadoc (from the BlueJ window, select Tools, then Project Documentation) and ensure that it is complete and correct. Part 2 Class Deck 1. Open the incomplete implementation of Deck in the BlueJ editor and read the documentation for the constructor and methods. Notice that this class has a single field called cards. The class must not define any additional fields - the fields called cards is sufficient. Of course, your constructor and methods may need to define one or more local variables. Don't litter your class with magic numbers. Several constants have been defined in this class - make sure you use them. Make sure you update the documentation at the beginning of the class (i.e., add your name as an author, and update the version number and date). 2. Write constructor Deck (), buildSuit (), isEmpty() and size (). Don't forget the javadoc comments (@param, @return). The constructor must call private method buildSuit () four times (once for each suit). Each time buildSuit () is called, 13 new cards will be added to the deck. The constructor does not shuffle the deck of cards. Compile the Deck class. After the class compiles without errors, compile DeckTest. Run the test cases in DeckTest. testCreate Deck should pass, but the other test cases will fail. 3. Write dealCard (). dealCard () should always remove and return the card at the front of the deck, i.e. the first card in the ArrayList. It should not randomly pick the card it will remove. Run all the tests in DeckTest. test Deal and testHas52Cards should now pass. If both tests fail, the problem is probably in your dealCard ( ) method. Iftest Deal passes but testHas52Cards fails, the problem is probably in your constructor or buildSuit () method (you're likely not initializing the deck with 52 different cards). Don't forget the javadoc comments (@param, @return). 4. Write shuffle (). The method should create one instance of java.util.Random() and repeatedly (at least 10,000 times) invoke nextInt (int n) to generate the positions of two cards in the deck to interchange. Run all the tests in DeckTest. testShuffle should now pass. Don't forget the javadoc comments (@param, @return). 5. Generate the javadoc and ensure that it is complete and correct. Part 3 - Class Hand 1. Open the incomplete implementation of Hand in the BlueJ editor and read the documentation for the constructor and methods. Complete the implementation of the class, including the javadoc comments. As you write each method, run the tests in HandTest to provide you with feedback. Notes: a. The class must not define any additional fields - the fields called cards is sufficient. Of course, your methods may need to define one or more local variables. b. Most of the methods in Hand will be very short; for the most part, they will simply call the appropriate method on the hand's ArrayList object. c. Notice that the String returned by toString () should have a single space between each number (card rank), and should have no leading or trailing spaces. 2. Generate the javadoc and check that it is complete and correct. Submission Submit Card.java, Deck.java, and Hand.java.
Expert Answer:
Related Book For
Financial Accounting and Reporting a Global Perspective
ISBN: 978-1408076866
4th edition
Authors: Michel Lebas, Herve Stolowy, Yuan Ding
Posted Date:
Students also viewed these programming questions
-
Background You have been asked to develop the logic for a version of a card game that has aspects similar to the popular card game Uno. The working title for the game is Quattro (as it has four...
-
Barbara buys 100 shares of DEM at $35 a share and 200 shares of GOP at $40 a share. She buys on margin and the broker charges interest of 10 percent on the loan. a. If the margin requirement is 55...
-
1. Two balls are thrown off a building with the same speed, one straight up and one at a 45 angle. Which statement is true if air resistance can be ignored? (a) Both hit the ground at the same time....
-
Nido Co. has a standing agreement with a supplier for purchasing car parts. The terms of the agreement are 3/15, n/30 from the invoice date of September 1. The company makes a purchase on September 1...
-
A Pepsi promotion encouraged consumers to collect Pepsi points and redeem them for merchandise. If they did not have quite enough points for the prize they wanted, they could buy additional points...
-
The following information is available for the pension plan of Radcliffe Company for the year 2014. Actual and expected return on plan assets ...... $ 15,000 Benefits paid to retirees ................
-
I wrote a relational model for the ER form, but I failed to normalize it. I separated customer contact from customer but I think there should be more. According to the EER chart given, is this...
-
Which series has the highest beta. BraveNewCoin Liquid Index for Bitcoin 1D BNC Trading Brave Ne Yellow Green Blue Orange
-
Brae Industries Inc. purchased a machine on January 2, 2020, with a cost of $175,000, with an expected useful life of five (5) years, and an estimated salvage value of $8,000. Brae depreciates all...
-
Information about Three investments as below Years 12345 5 Probability Investment A Investment B Investment C 0.1 300 850 500 0.2 350 560 600 0.35 280 450 700 0.2 0.15 460 680 800 500 700 900 If the...
-
I want a program code to Modeling a cellphone animated model using CPP and openGL library?
-
Let p(x)=2x+2x + 5x + 5 a) Factor polynomial p(x). b) Solve the equation p(x) = 0.
-
how does recurision work in python? how do you code the for the recurision part? please explain how and shows example?
-
Come up with a programming idea. This can be an educational or social activity. Explain your goal, the steps you would take to plan an inclusive event, what resources would you use, how would you...
-
I. Def. An ideal M of a ring R mini mal i deal of R if is said to be (i) M # (0) (ii 3 no i deal J of R s. (0)
-
When the Department of Homeland Security created a color-coded system to prepare government officials and the public against terrorist attacks, what did it do right and what did it do wrong?
-
Saint Gobain, a France-based global enterprise, is involved in the production and sales of flat glass and building materials. It reports in its financial statements for the year ended 31 December...
-
Gerry Weber International AG is a German group active in the design, manufacture and retail of womens clothing. The following data concerning the parent company were excerpted from the 2011 annual...
-
Select the right answer (only one answer is possible, unless otherwise indicated). 1 The objectives of financial reporting for a business entity are based on which elements (a) Generally accepted...
-
Select an information system with which you are familiar, and which you feel needs to be improved, based upon your experiences as an employee, customer, other system user, or system owner, Switch...
-
You have learned the importance of making sure that requirements are correctly identified. Hut how do you know when you have a correct requirement-that is, what criteria must each requirement meet in...
-
Prepare a full feasibility analysis, including Economic, Operational, Schedule, Legal, and Technical analyses for the system you are suggesting in problem 1. Your analysis should be no more than 30...
Study smarter with the SolutionInn App