Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class that represents a playing card, with values for the four suits, plus none for the joker, and values for the thirteen card

Create a class that represents a playing card, with values for the four suits, plus none for the joker, and values for the thirteen card ranks, plus the joker. Make the default constructor set a default value for a card and demonstrate this by calling the default constructor to create a card. Construct a deck of cards and deal some cards and display them.

Create a new project for the assignment.

Create a new class called Card. The Constructors from superclass check box will create a constructor stub in the code.

Create an Enumerated Type in a new source file called Suit with the values NONE, CLUBS, HEARTS, SPADES, DIAMONDS.

Create an Enumerated Type in a new source file in the same package as the Card class, called Rank with the values JOKER, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE.

In the class Card,

Create a class attribute (field) called rank of type Rank.

Create a class attribute (field) called suit of type Suit.

Create getters and setters for these fields. Make the setters private, since we only want the constructor to set the card Suit and Rank (we would not want a programmer or user to set more than one ACE of CLUBS for instance).

Create a constructor that accepts a Suit and a Rank and use those values to set the attributes.

In the default constructor, initialize the suit and Rank attributes. Use the this constructor to call the constructor created in the previous step and initialize the rank and suit with a value of your choice (for example: Rank.ACE, Suit.CLUBS).

In the main method of the class, construct a default Card to demonstrate the default constructor initialization.

Also construct a few additional cards using the Suit and Rank constructor. Use local variables to hold the objects.

Using the toString() method from Enumerated Types, print the Suit and Rank of each Card created.

Create a Deck class that contains a field that is an array of fifty four cards (Containment).

Create a constructor on the Deck class that initializes the array of cards with the standard deck and two jokers, using for loops that iterate over the Suit and Rank values and set the array members with the appropriate Card constructor. Remember that the two Jokers only exist as 'NONE' suits and only the Jokers use the 'NONE' suit. There are many possible solutions for creating only two jokers. I used an iterator, left them out of the loop and added them in the beginning, individually. Use an if statement to exclude the jokers within a for each loop and add them before or after.

Create a toString() method in the Deck class, using another for loop to print all the Cards in the array by calling the toString() method on each card. This method asks the Card to print its rank and suit by only calling toString() on the Card object. There should be no reference to Rank or Suit anywhere in this method. Let Card's toString() method do the work (Delegation).

Create a main method in the Deck class that creates a Deck. Then print the deck using System.out.println(). This will call Deck's toString() method, which will call toString() on each Card, printing the entire deck. The main method in the Deck class is the method to set for the jar in this assignment.

As required for all assignments from now on

validate the proper functionality using the example answers below and review the Concepts and Ideas checklist

format the code

add a comment at the top of the file that reads @ author and your name

build the javadocs

build the jar file using the Deck class as the main method

Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.

Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.

submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Example:

JOKER JOKER TWO of CLUBS THREE of CLUBS FOUR of CLUBS FIVE of CLUBS SIX of CLUBS SEVEN of CLUBS EIGHT of CLUBS NINE of CLUBS TEN of CLUBS JACK of CLUBS QUEEN of CLUBS KING of CLUBS ACE of CLUBS TWO of HEARTS THREE of HEARTS FOUR of HEARTS FIVE of HEARTS SIX of HEARTS SEVEN of HEARTS EIGHT of HEARTS NINE of HEARTS TEN of HEARTS JACK of HEARTS QUEEN of HEARTS KING of HEARTS ACE of HEARTS TWO of SPADES THREE of SPADES FOUR of SPADES FIVE of SPADES SIX of SPADES SEVEN of SPADES EIGHT of SPADES NINE of SPADES TEN of SPADES JACK of SPADES QUEEN of SPADES KING of SPADES ACE of SPADES TWO of DIAMONDS THREE of DIAMONDS FOUR of DIAMONDS FIVE of DIAMONDS SIX of DIAMONDS SEVEN of DIAMONDS EIGHT of DIAMONDS NINE of DIAMONDS TEN of DIAMONDS JACK of DIAMONDS QUEEN of DIAMONDS KING of DIAMONDS ACE of DIAMONDS

This is just my example, feel free to be creative.

My hand contains:

ACE of CLUBS

KING of CLUBS

QUEEN of CLUBS

JACK of CLUBS

TEN of CLUBS

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions