Write a class called card that contains instance data

Assignment Help Programming Languages
Reference no: EM131938518

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.

Reference no: EM131938518

Questions Cloud

What is the annual investment rate of return : What is the annual investment rate of return that Troy must obtain if he deposits $250 at the end of every month for 10 years? Please provide the authentic.
How do think the new plan would affect your business : Depending on who you listen too the results of the score were either positive or negative for U.S. citizens with respect to health care.
What will your annual loan payment be : Required: What will your annual loan payment be? (Do not round your intermediate calculations.)
What would be a positive course of action for a business : What if for some reason a business received some justified or not justified negative comments by a customer on social media.
Write a class called card that contains instance data : Write a class called Card that contains instance data to represent playing card with face and a suit. Create a class called DeckofCards that stores 52 objects.
What will be the expected return and the beta : What will be the expected return and the beta of your portfolio after you purchase the new stock? Please include the steps in order for better understanding.
Estimate the mean life of the bulbs : You receive a request from a team of product engineers who are working on the design of a projector that your company manufactures.
What arbitrage would you take : Assume that the gama index spot price is at 12,000, the risk free rate is 3% and the continuous dividend yield on the index is 0%.
Why were the four components of this time bomb considered : Why were the four components of this time bomb considered ingenious? Name the two pieces of evidence you think are most damaging to this employee.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd