Computer Science 1260
January 30, 2019 / Classwork - Cards / Due: ______

Eclipse Project

Create a new Eclipseproject named Cards with a package named cards. The cards package should contain all of the .java files described below. Be sure to document EVERYTHING as required in the course documentation standards.

Face and Suit Enumerated Types

Define publicenumeratedtypes named Face and Suit that represent the faces (Ace, Seven, Queen, Three, etc.) and the suits (Clubs, Diamonds, Hearts, and Spades) found in an ordinary deck of playing cards. The definitions for Face and Suitshould be placedin separate files namedFace.java and Suit.java, respectively.

Card Class

A class named Card is to be created. This class models onesingle card out of an ordinary deck of playing cards. It should have two privateattributes:

  • face
  • suit

whose values come from publicenumeratedtypesthat you definedabove named Face and Suit, respectively. Note that these are NOTStrings or integers.

The Card class should have threeconstructors:

  • The default constructorinitializes a “default” card– you may choose any face and any suit as your default
  • A copyconstructor with a header of public Card (Card existingCard). This constructor initializes a new Card as a duplicate of an existing card (the parameter). The body of this method should simply copy the attributes of existingCard into their counterparts in the Card being initialized (a deep copy).
  • The parameterizedconstructorpublic Card (int n)takes an non-negative integerparametern and converts it to appropriate subscripts using the mod (%) operator. For the parameterizedconstructor, appropriate values for thesuit and faceclass attributesshould be generated from constructor’s integer parametern using the code below.

face = Face.values( )[n % 13];

suit = Suit.values( )[n % 4];

The Card class should also have a toString method that returns a String representing an appropriate displayable phrase such as “the Jack of Diamonds” or “the Deuce of Hearts”identifying the particular Card.

Driver Class

A driver class is to be created to demonstrate the functionality of the Card class.

  1. In it, createand display a “defaultCard” using the defaultconstructor. Label it as the default in the display (for example, The default card is the Deuce of Clubs). See sample output at the end of this document.
  2. Then, in a loop, prompt the user to type anon-negativeinteger. Take the user’s integer and create a Card object using the parameterizedconstructor. Display the Card. Repeat until the user indicates a desire to stop.
  3. Finally, in the driver class, create a privatestaticmethod named showDeck that uses afor-loop to create and display allpossible 52 Card objects. Invoke this method at the end the main method. Give a title/heading of “All 52 Cards Follow:”

UML Diagram

A UML diagram for this exercise is given below.

Proper Documention and Code Style is REQUIRED

Make sure all code filesarefully documented– see the course documentation policies posted on the course website for the conventions and requirements including examples of proper documentation. Proper documentation includes following the naming conventions for classes, files, methods, variables, constants, and other identifiers.

Deliverable

Make sure you complete this exercise. Show your running program to the instructor or TA before you leave today. There is nothing to turn in today, but save your work as we will build on this next week.

Sample Output

Playing Card ClassPage 1