Assignment Number: a6

Folder Name: LinkedWar

Create the classes War, Card, Deck, ListNode, Queue, LinkedQueue, and EmptyStructureException to play War.  These classes can be found in the textbook: Data Structures and Algorithms in Java by Peter Drake on pp. 108-113, 120-124, 159, and 166.

Make the following modifications to War

1. The highest card is an Ace and the lowest card is a Two.

2. Use a linked representation for the Queue using the classes

ListNode and LinkedQueue.

3. Change stack1 and stack2 in to queue1 and queue2. 

There will be no Stack and LinkedStack in War.

4. The queues in the program are really pseudoqueues.  To access the

rear of the queue, using a new queue method like peek or getLastElement, to get the last element put in the queue to determine who wins the round.

5. Add a counter to print the Round Number and to print how many cards are in each player’s hand.  Add a size variable to the LinkedQueue and a LinkedQueue method getSize which return the size of the queue.

6. In the Deck class, instead of initializing the cards array with nested for loops and then shuffling the deck, read the cards in from a file in your War folder called “Cards”.  The Cards file will have 52 lines (one for each card) and each line will contain 2 characters like Ad, 2c, Js, 9d, etc.  Translate the characters to rank and suit and put them in the cards array.  Use the FileInputOutput class as an example how to do I/O from files. 

7. The dialog of the game will look something like this.



    • Posted: 3 years ago
    A+ Work

    Purchase the answer to view it

    Save time and money!
    Our teachers already did such homework, use it as a reference!