Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java programming anent C of 34 2 E computer Science Theo Antistatwiatrom Theoph- 54 AM 18 minutes ago) Although our Hand class could be used

Java programming image text in transcribed
image text in transcribed
image text in transcribed
anent C of 34 2 E computer Science Theo Antistatwiatrom Theoph- 54 AM 18 minutes ago) Although our Hand class could be used in any type of card game, we will implement methods that give a Hand objeca foundation for recognising Poker hands, such as .four-of-a-kind a hand that includes four cards win the same rank legfour 73 . fusha hand in which all of the cards have the same site. Heart three-of-a-kind a hand that has three cards of the same rank (three Jacks wo pair hand with two separate pain of cards with the same rak.tws and two 105). para hand with two cards with the same make two 45. and high and a hand with one of the above special characteristics and thus its value is based on the value of its high card Ultimately you should write methods that identify the types of hands above for a Hand object. I put integer class constants for each of the hand types listed above in Handjava for reference. Note that the numbers used for the hand-type constant increase with the value of the hand type. In other words, the more valuable a type of hand is the Niger the constant we have used for it. For example, four-kind is the highest-valued hand type that the dass wil support, and we have given that and type the highest numerical In Handjava give you declarations of the following fields cards, an array of type and the stores the cards belonging to the hand, nuncards, an integer that indicates how many cards are currently in the hand Do not add any additional fields to the class. 1. Add a constructor to Hardwathakes a single integer parameter specifying the maximum number of cards that the hand holds. For example, if you are creating a Hand for a game of Blackjack, you might want to slow room for as many as 15 cards, which I could do in client code by calling the constructor us follows: Hand new Hand (15) Your constructor should create an array that is capable of storing the specified number of cards, assign in to the floid cards, and initialize the nuncards froid to reflect that the hands tay empty Many of your hand methods will need to process the cards array Handjava contains an example of such a method. It is called getTotalValue, and it computes and ure the sum of the values of the cards in the cards array. If the Hand is currently empty Lohas no cards), the method returns 0. 2 Your Handdess should include instance method getards that returns the number of rotat 2. Your Hand class should include an instance method getNuncards that retums the number of cards that are currently in the hand. 3. Your Hand class should include an instanon method addCard that takes a Card object as a parameter and adds it to the Hand, putting it in the next available position in the array-filing the array from lon to right. The method should also make whatever other changes are needed to the state of the Hand object. If the parameter is null, tho method should throw an illegalArgumentException. If the array is full the method should throw an illegal toxoption, 4 Your Hand class should include an instance method toString that returns a String representation of the Hand object. The returned String should have the form "cardo card, Gardn", where cardo, card, etc. are the abbreviations of the cards in the hand. Note that the Card can has a Abbrev method you can cut For example, la Hand object contains a 3 of Hearts and a Jack of Spades, this method should retum *3H, JS". Now that the abbreviations should be separated by commus and the hand as a whole should be surrounded by brackets & Your Hand class should include an instance method getcard that takes an index 1 and returns the card at that position in the cards array of the index is invalid or if there is no card at the specified position in the array, the method should throw an llegalArgumentException 6. Your Hand class should include an instance method playcard that takes an index 1 and plays the card at that position in the cards array. Lo getCard, this method wil return the specified Card object. It will also remove the Card object from the array in doing so, the method should shift over any cards that come after the removed card in the array so as to fill in the gap" created by the removed card. For example, assume that you have a Hand object initialed as follows: Hand hi new Hand (5) hi.adacard new Cardis, Card.DIAMONDS)); // 5 of Diamonds hi.addCard new CardiCard. ACE, Card. SPADES)); // Ace of Spades hi.addCard(new Card(Card. KING, Card. HEARTS)); // King of Hearts Ahur these statements, there are threo Card objects in the cards array: a 5 of Diamonds in position, an Ace of Spades in position, and a Kind of Hearts in poulton 2. To play the 5 of Diamonds, we can do the following: Card playedCard = h.playCard(0); // play the card in position After this method returns, the 5 of Diamonds will be assigned to the variable playedCard. In addition, the contents of the cards array will have changed. The 5 of Diamonds will no longer be in the array, the Ace of Spades will now be in position (shifted one position to the left), and the King of Hearts will now be in position 1 (shihed one position to the left). The method should also make whatever other changes are needed to the state of the Hand object. If the index specified by the parameter is invalid or if there is no card at the specified position in the array, the method should throw an ilegalArgumentException 7. Your Hand class should include an instance method highCard that returns the Card object in the Hand with the largest value. This task is similar to the array processing code for finding the maximum of the array values from the Java Reference Card, but instead of returning the largest value in the array, your mothed should return the Card object with the largest value. For example, given the Handhi defined above, hl. highCard) would return the Card object representing the King of Hearts because that is the card with the largest value in the hand. If there are multiple cards that are tied for the largest value the method should retum the one that comes closest to the beginning of the cards array & Your Hand class should include an instance method nuncard to firank that takot an a parameter an integer specifying a rank and returns trumber of cardente Hand with that rank. The method does not need to check if the parameter is valid. If the parameter is invalid, the method can simply retum once it finds no campies of that rank in the hand. 9. Your Hand class should include an instance method hasFlush that returns true it all of the cards in the Hand have the same suit and false if they do not. Note that this method does not need to exclude hands that would be classified as something other than a flush, as long as the cards are all of the same sut anent C of 34 2 E computer Science Theo Antistatwiatrom Theoph- 54 AM 18 minutes ago) Although our Hand class could be used in any type of card game, we will implement methods that give a Hand objeca foundation for recognising Poker hands, such as .four-of-a-kind a hand that includes four cards win the same rank legfour 73 . fusha hand in which all of the cards have the same site. Heart three-of-a-kind a hand that has three cards of the same rank (three Jacks wo pair hand with two separate pain of cards with the same rak.tws and two 105). para hand with two cards with the same make two 45. and high and a hand with one of the above special characteristics and thus its value is based on the value of its high card Ultimately you should write methods that identify the types of hands above for a Hand object. I put integer class constants for each of the hand types listed above in Handjava for reference. Note that the numbers used for the hand-type constant increase with the value of the hand type. In other words, the more valuable a type of hand is the Niger the constant we have used for it. For example, four-kind is the highest-valued hand type that the dass wil support, and we have given that and type the highest numerical In Handjava give you declarations of the following fields cards, an array of type and the stores the cards belonging to the hand, nuncards, an integer that indicates how many cards are currently in the hand Do not add any additional fields to the class. 1. Add a constructor to Hardwathakes a single integer parameter specifying the maximum number of cards that the hand holds. For example, if you are creating a Hand for a game of Blackjack, you might want to slow room for as many as 15 cards, which I could do in client code by calling the constructor us follows: Hand new Hand (15) Your constructor should create an array that is capable of storing the specified number of cards, assign in to the floid cards, and initialize the nuncards froid to reflect that the hands tay empty Many of your hand methods will need to process the cards array Handjava contains an example of such a method. It is called getTotalValue, and it computes and ure the sum of the values of the cards in the cards array. If the Hand is currently empty Lohas no cards), the method returns 0. 2 Your Handdess should include instance method getards that returns the number of rotat 2. Your Hand class should include an instance method getNuncards that retums the number of cards that are currently in the hand. 3. Your Hand class should include an instanon method addCard that takes a Card object as a parameter and adds it to the Hand, putting it in the next available position in the array-filing the array from lon to right. The method should also make whatever other changes are needed to the state of the Hand object. If the parameter is null, tho method should throw an illegalArgumentException. If the array is full the method should throw an illegal toxoption, 4 Your Hand class should include an instance method toString that returns a String representation of the Hand object. The returned String should have the form "cardo card, Gardn", where cardo, card, etc. are the abbreviations of the cards in the hand. Note that the Card can has a Abbrev method you can cut For example, la Hand object contains a 3 of Hearts and a Jack of Spades, this method should retum *3H, JS". Now that the abbreviations should be separated by commus and the hand as a whole should be surrounded by brackets & Your Hand class should include an instance method getcard that takes an index 1 and returns the card at that position in the cards array of the index is invalid or if there is no card at the specified position in the array, the method should throw an llegalArgumentException 6. Your Hand class should include an instance method playcard that takes an index 1 and plays the card at that position in the cards array. Lo getCard, this method wil return the specified Card object. It will also remove the Card object from the array in doing so, the method should shift over any cards that come after the removed card in the array so as to fill in the gap" created by the removed card. For example, assume that you have a Hand object initialed as follows: Hand hi new Hand (5) hi.adacard new Cardis, Card.DIAMONDS)); // 5 of Diamonds hi.addCard new CardiCard. ACE, Card. SPADES)); // Ace of Spades hi.addCard(new Card(Card. KING, Card. HEARTS)); // King of Hearts Ahur these statements, there are threo Card objects in the cards array: a 5 of Diamonds in position, an Ace of Spades in position, and a Kind of Hearts in poulton 2. To play the 5 of Diamonds, we can do the following: Card playedCard = h.playCard(0); // play the card in position After this method returns, the 5 of Diamonds will be assigned to the variable playedCard. In addition, the contents of the cards array will have changed. The 5 of Diamonds will no longer be in the array, the Ace of Spades will now be in position (shifted one position to the left), and the King of Hearts will now be in position 1 (shihed one position to the left). The method should also make whatever other changes are needed to the state of the Hand object. If the index specified by the parameter is invalid or if there is no card at the specified position in the array, the method should throw an ilegalArgumentException 7. Your Hand class should include an instance method highCard that returns the Card object in the Hand with the largest value. This task is similar to the array processing code for finding the maximum of the array values from the Java Reference Card, but instead of returning the largest value in the array, your mothed should return the Card object with the largest value. For example, given the Handhi defined above, hl. highCard) would return the Card object representing the King of Hearts because that is the card with the largest value in the hand. If there are multiple cards that are tied for the largest value the method should retum the one that comes closest to the beginning of the cards array & Your Hand class should include an instance method nuncard to firank that takot an a parameter an integer specifying a rank and returns trumber of cardente Hand with that rank. The method does not need to check if the parameter is valid. If the parameter is invalid, the method can simply retum once it finds no campies of that rank in the hand. 9. Your Hand class should include an instance method hasFlush that returns true it all of the cards in the Hand have the same suit and false if they do not. Note that this method does not need to exclude hands that would be classified as something other than a flush, as long as the cards are all of the same sut

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

Students also viewed these Databases questions

Question

Briefly explain Independent Vs Mutually Exclusive Projects

Answered: 1 week ago