Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Assignment

Write a class called Card that contains instance data to represent a playing card with a face and a suit.

• Recall: A card can have one of 13 faces:
• Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen and King
• Recall: A card be part of 4 suits:
• Clubs, Diamonds, Hearts and Spades

Next, create a class called DeckofCards that stores 52 objects of the Card class. Include methods here to shuffle the deck, deal a card and determine if the deck has cards remaining.

• The shuffle method should assume that you have a full deck

Finally, Create a driver class called CardDriver, whose main method shuffles the deck, asks the user for the number of cards they want, and deals that number of cards, printing each card as it is dealt.

In the Card class you will need:

• Private members of the class to store:
• face value as an integer
• Integer face values can be 1 to 13 representing the strings Ace to King.
• suit value as an integer
• Integer suit values can be 1 to 4 representing the 4 suits.
• face name as a String and
• suit name as strings

• Optional: You can create constants to represent the faces and the suits if you want (and you can make these static!), but these constants are separate private members (i.e. they do not replace the face and suit variables of the class)

• A constructor that accepts the integer face values (1 -13) and the integer suit values (1 - 4) to represent a card

• Two private methods (support methods) to assign a string value to the card, based on the face and suit value (Example: if the face value is 4 and the suit value is 2 then that card should be "Four of Clubs".)

• The first private method should use a switch statement to assign a string value to each of the possible face values.

• Here, you should have 13 cases, no default is needed.

• The second private method should use a switch statement to assign a string value to each of the possible suit values.

• Here, you should have 4 cases, no default is needed.

• Your constructor should call both these support methods in its definition.

• A toString method to output the String representation of the card.

In the DeckofCards class you will need:

• Private members of the class to store:

• An array of 52 card objects

• A integer variable to keep track of the numberofCards in the deck

• A constructor that accepts no parameters. The constructor should:

• Instantiate the Card array to hold 52 cards

• Use a nested loop to instantiate each of the card objects in that array

• The first loop should control the face values

• The second loop should control the suit values

• The body of the loop should use the new operator for every position in the card array (and should pass an integer face and suit value to the constructor)

• A method to deal a card

• This method is a value returning method of type Card, and accepts no parameters

• If the number of cards in the deck is greater than zero, then return a card from the array

• Otherwise return null (this is needed to ensure that something is returned)

• A method to see if the deck has cards remaining

• This method returns true if the number of cards in the deck is greater than zero, and false otherwise. It accepts no parameters.

• A method to shuffle the deck

• This method shuffles by swapping random pairs of cards multiple times

• It accepts no parameters and returns no values

• It uses a random object to generate a values between 0 and 51 (representing the positions in the Card array)

• You will need a temp Card object as well as two local variables to store the generated values

• Pseudocode for this method is shown below:

// create random object here
Card temp;
int a, b;
for (9999 repetitions - for fun and better shuffling)
{
a = (randomly generated value)
b = (randomly generated value)
// swap algorithm shown below
// cards is array of Cards created by constructor
temp = cards[a];
cards[a] = cards[b];
cards[b] = temp;
}

In the CardDriver program, you will need:

• An object of type DeckofCards that creates a deck of Cards

• This object will be used to shuffle the deck in this program

• A Scanner object to get information the number of cards the user wants from the deck

• A local variable to store the number of cards the user wants

• A while loop to print out the cards

• The loop should run while the value in the loop control variable is less than the number of cards requested by the user AND there are still more cards in the deck.

• Use the boolean method from the DeckofCards class as part of the condition. In the event the user requests more than 52 cards, this method should stop dealing after 52 cards have been dealt.

• Use the deal method from the Deck of Cards class in the body of the loop.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92777174

Have any Question?


Related Questions in Programming Language

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As