The Stack and Java Queue ADTs Idiot’s Delight Game

Order Description

Objectives:

After completing this assignment, the student should be able to:

Create and use a Stack object. (in the folder)

Create and use a Queue object.  (in the folder)

Create thorough test cases in jUnit.

 

Problem Specifications:

In this assignment, you are going to create a card game and jUnit test cases to test the card game. The specifications for the game is as follows.

Idiot's Delight

Players: 1

Objective: To clear all the cards off the table.

Setup: Shuffle a deck of cards and deal four cards face up in a row, forming four stacks.

Play: On your turn, you may do any one of the following:

- if there are two cards of the same rank showing, discard both of them

- if there are two cards of the same suit showing, discard the one with the lower rank

- deal four new cards, one on top of each stack

 

Design

You will create a Card class and a Deck class to be used by the game. The toString() method will return the rank and suit of the card.

The Card class will represent a single playing card and have a rank and a suit.

The Deck class will represent a card deck of 52 cards. The constructor will create an unshuffled list of all 52 cards. The shuffle() method with rearrange the cards into a randomly sorted queue. The deal() method will remove the first card from the queue and return it to the client class. The size() method will return the number of cards that have not yet been dealt.  For testing purposes, you will also need the ability to not shuffle the cards, and instead create a test deck in the order you require to test your scenario.

The IdiotsDelight class will contain a Deck object and an array of four stack objects of cards representing the four stacks of cards dealt in the game. The deal() method will deal one card on the top of each stack. The removePair() method will remove two cards of the same rank from the top of the stacks. If there are not two cards of the same rank, removePair() method will throw an IllegalMoveException. The removeLowCard() method will remove the card with the lower rank if there are two cards of the same suit showing. If there are not two cards of the same suit, the removeLowCard() method will throw an IllegalMoveException. The toString() method will return the value on the card on the top of each stack. If a stack is empty, it will return "--" for that stack.

The IdiotsDelightGame class will play the Idiot's Delight game.

The java files for the various classes of stacks and queues. You may use whichever of these provided implementations of stacks and queues that you feel is most appropriate.

Partial Sample runs: IdiotsDelightGame

Welcome to Idiot's Delight!

The object of the game is to clear all the cards off the table.

Each play you have the option of:

D - deal four more cards.

S - if there are two cards of the same suit showing, discard the one with the lower rank.

R - if there are two cards of the same rank showing, discard both cards.

 

The tops of the stacks are: 9H, JC, 8C, 7H,

There are 48 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

s

The tops of the stacks are: 9H, JC, 8C, --,

There are 48 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

s

The tops of the stacks are: 9H, JC, --, --,

There are 48 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

d

The tops of the stacks are: JS, 7D, 6S, 4H,

There are 44 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

s

The tops of the stacks are: JS, 7D, --, 4H,

There are 44 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

d

The tops of the stacks are: 6C, QC, QS, 7S,

There are 40 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

r

The tops of the stacks are: 6C, 7D, --, 7S,

There are 40 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

d

The tops of the stacks are: 8D, AH, 4D, 4C,

There are 36 cards left in the deck.

What do you want to do (D - deal, S - discard lowest rank, R - discard two cards with same rank, Q - quit?

 

To be handed in:

1. A Word document containing the list of test cases for the program. A simple numbered list of test cases is acceptable, where each test describes what scenario you will test.  You will also need to think about and describe in your test case document how you are going to test these scenarios.  (Provide some sample Decks that will allow you to test the scenarios.)  

 

2. Complete junit test cases to test the scenarios developed, using test decks.

 

3. The code for the assignment.  The username_B31_A03_Stacks_Queues folder containing the java files for the project, the junit tests and the test case plan.

Marking Scheme:

 

Mark

Out of

Class diagram

 

5

Test case scenarios

 

10

Junit Test Cases

 

25

Card class

 

5

Deck class

 

15

IdiotsDelight class

 

38

IllegalMoveException

 

2

IdiotsDelightGame class

 

10

IdiotsDelight Program execution

 

10

Organization

 

5

Total

 

125

Organization Marks:

Marks will be given for organization. This includes:

- naming files and folders according to the department standards

- giving meaningful names to variables, classes, objects and methods

- formatting and indenting Java classes using the Eclipse format tool

- including all required files in the submitted assignment folder.