Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART A: LinkedLists (50 marks) The card game 99 (Ninety Nine) is a simple turn-based multiplayer game, where each player takes a turn playing a

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

PART A: LinkedLists (50 marks) The card game 99 (Ninety Nine) is a simple turn-based multiplayer game, where each player takes a turn playing a card from their hand, and adds the value of the card to the running total. The player who causes the total to go over 99 loses the round. Create a program that simulates a round of 99: Players are dealt 3 cards. The point total starts at zero and each card adds its face value in points (example: a 5 is worth five points, a face card is worth 10 points) except for certain cards that have special values or meanings: A4 reverses play and does not change the total number of points) A9 is a pass (and does not change the total number of points) A 10 subtracts 10 points from the total A King takes the point total to 99 (or keeps it 99 if the total is already 99) An Ace adds either 1 or 11 points, announced by the player who plays it . After each card is played, the player announces the new total to the table and draws a replacement card. Each player must play a card without sending the total number of points higher than 99. If a player cannot play a card that keeps the total at or less than 99, that player loses a token and the round ends. 1. Develop a generic CircularDoublyLinkedList - Use the circularly and doubly linked list classes from our notes as a basis. Start with the DLL and think of how it can work circularly. Sentinels are not required, only a reference to the last node Node will have references to the next and previous nodes addBetween and remove () private utilities will be used, all adding and removing will work like doubly A boolean field, is Forward, represents the direction of rotation Your CircularDoublelinked List class will support the following public methods: size() Returns the number of elements in the list. i sEmpty() Returns true if the list is empty, and false otherwise. first() Returns (but does not remove) the first element in the list. last (0) Returns (but does not remove) the last element in the list. addFirst(e) Adds a new element to the front of the list. addLast (e) Adds a new element to the end of the list. removeFirst() Removes and returns the first element of the list. removeLast() Removes and returns the last element of the list. rotate() Advances to the next element in the list based on direction reverse() Changes the direction 2. Create the following classes: 1 1 Game Sim Deck is played with 1 1 involves V consists of V * * 1 Player Card plays a) Card contains 2 enum types: Suit: CLUBS, SPADES, HEARTS, DIAMONDS RANK: numbers TWO to TEN, JACK, QUEEN, KING, ACE b) Deck stores an ArrayList (from Java API) of Cards Upon initialization a deck of 52 cards should be built. create and add all 52 cards in a deck (i.e. each rank of each suit). Include a shuffle () method that shuffles the cards - Include a method that removes a card from the top (front) of the deck and returns the Card instance c) Player stores the player name and an ArrayList of Cards as their hand. Include a method to play a card (removes and returns a given card from the hand). d) GameSim class that runs the game *Note - most of the work will be done here. As1 PartA_Driver should have minimal code: e.g. declare/create a GameSim instance, add players, initiate game play Fields: a CircularDoublyLinkedList of players a Deck of cards the running total of the round any other field required to manage the game Upon instantiation of a game, set up the list of players (use 4 players for your demo/sample data), create the deck, shuffle and deal 3 cards to each player. Begin the game with the first player in the list. Each player will have their turn when positioned at the head of the list. Notes: - Use enhanced enums to set the value for a face card. Mark special cards through this value. If the player plays an ACE, play 11 unless it will cause them to lose the round. When faced with possibly going over 99, the player should play a card that prevents them from losing. Otherwise any card can be played. Note in the sample output below, the first card in the hand is played. To format output, include a String field display and override the enum's toString(). Use unicode values \u2663, \u2660, \u2665, \u2666 for clubs, spades, hearts and diamonds respectively. Sample output: Let's play 99!!! Players: Simba, Nala, Timon, Pumbaa 6 (Simba's hand: 104, Simba plays 104 The total is -10 (Nala's hand: A+, 2, 5) Nala plays Ad The total is 1 (Timon's hand: 44, 4., 5.) Timon plays 44 Game reverses direction (Nala's hand: 2, 5, K) Nala plays 2 The total is 3 (Simba's hand: 69, Q., K.) Simba plays 6 The total is 9 (Pumbaa's hand: 104, 9, 8) Pumbaa plays 10% The total is -1 (Timon's hand: 4., 5., 9) Timon plays 4. Game reverses direction 3 . (Pumbaa's hand: 9, Pumbaa plays 9. Simba skips a turn (Nala's hand: 5, K, 54) Nala plays 5 The total is 4 34) (Timon's hand: 5., 9 Timon plays 5. The total is 9 (Pumbaa's hand: 8., Pumbaa plays 8. The total is 17 (Simba's hand: g., K., 3) Simba plays Q The total is 27 (Nala's hand: K, 54, 34) Nala plays K The total is 99 (Timon's hand: 9, 34, 3.) Timon plays 9 Pumbaa skips a turn (Simba's hand: K., 3, 10) Simba plays K The total is 99 (Nala's hand: 5, 39, 2) Nala plays 5 The total is 104 Nala loses this round PART B: Stacks (30 marks) Create a program that simulates the undo/redo features of an application. Implement a simple calculator that asks the user for the basic arithmetic operation that they would like to perform on the last result. Your program will: Prompt the user to enter an initial number (first operand) Then prompt the user for the next operator and second operand evaluate the expression present the user with the result, which will be the new first operand This will continue until the user chooses to quit, or undo (redo) an operation The undo operation restores the last state. The redo operation restores the next state if an undo was previously performed. 1. Create the generic ArrayStack that implements the Stack interface using an array. 2. Create a driver class called As 1Parts_Driver and any other classes/methods that you may require. You must use two stack objects to hold items that will restore the states based on the function (undo "z" or redo "y") selected. Allow the user to quit ("q") anytime. Sample output: Simple Calculator: type z to undo, y to redo, q to quit Enter the first number: 10 Enter the next operation on 10: + 2 = 12 Enter the next operation on 12: - 3 = 9 Enter the next operation on 9: Z UNDO: 12 Enter the next operation on 12: z UNDO: 10 Enter the next operation on 10: 10 = 100 Enter the next operation on 100: / 5 = 20 Enter the next operation on 20: + 4 = 24 Enter the next operation on 24: z UNDO: 20 Enter the next operation on 20: Z UNDO: 100 Enter the next operation on 100: REDO: 20 Enter the next operation on 20: y REDO: 24 Enter the next operation on 24: y Nothing to redo. Enter the next operation on 24: + 6 = 30 Enter the next operation on 30: z UNDO: 24 Enter the next operation on 24: Z UNDO: 20 Enter the next operation on 20: z UNDO: 100 Enter the next operation on 100: z UNDO: 10 Enter the next operation on 10: z Nothing to undo. Enter a number: 12 Enter the next operation on 12: 9 Goodbye! PART A: LinkedLists (50 marks) The card game 99 (Ninety Nine) is a simple turn-based multiplayer game, where each player takes a turn playing a card from their hand, and adds the value of the card to the running total. The player who causes the total to go over 99 loses the round. Create a program that simulates a round of 99: Players are dealt 3 cards. The point total starts at zero and each card adds its face value in points (example: a 5 is worth five points, a face card is worth 10 points) except for certain cards that have special values or meanings: A4 reverses play and does not change the total number of points) A9 is a pass (and does not change the total number of points) A 10 subtracts 10 points from the total A King takes the point total to 99 (or keeps it 99 if the total is already 99) An Ace adds either 1 or 11 points, announced by the player who plays it . After each card is played, the player announces the new total to the table and draws a replacement card. Each player must play a card without sending the total number of points higher than 99. If a player cannot play a card that keeps the total at or less than 99, that player loses a token and the round ends. 1. Develop a generic CircularDoublyLinkedList - Use the circularly and doubly linked list classes from our notes as a basis. Start with the DLL and think of how it can work circularly. Sentinels are not required, only a reference to the last node Node will have references to the next and previous nodes addBetween and remove () private utilities will be used, all adding and removing will work like doubly A boolean field, is Forward, represents the direction of rotation Your CircularDoublelinked List class will support the following public methods: size() Returns the number of elements in the list. i sEmpty() Returns true if the list is empty, and false otherwise. first() Returns (but does not remove) the first element in the list. last (0) Returns (but does not remove) the last element in the list. addFirst(e) Adds a new element to the front of the list. addLast (e) Adds a new element to the end of the list. removeFirst() Removes and returns the first element of the list. removeLast() Removes and returns the last element of the list. rotate() Advances to the next element in the list based on direction reverse() Changes the direction 2. Create the following classes: 1 1 Game Sim Deck is played with 1 1 involves V consists of V * * 1 Player Card plays a) Card contains 2 enum types: Suit: CLUBS, SPADES, HEARTS, DIAMONDS RANK: numbers TWO to TEN, JACK, QUEEN, KING, ACE b) Deck stores an ArrayList (from Java API) of Cards Upon initialization a deck of 52 cards should be built. create and add all 52 cards in a deck (i.e. each rank of each suit). Include a shuffle () method that shuffles the cards - Include a method that removes a card from the top (front) of the deck and returns the Card instance c) Player stores the player name and an ArrayList of Cards as their hand. Include a method to play a card (removes and returns a given card from the hand). d) GameSim class that runs the game *Note - most of the work will be done here. As1 PartA_Driver should have minimal code: e.g. declare/create a GameSim instance, add players, initiate game play Fields: a CircularDoublyLinkedList of players a Deck of cards the running total of the round any other field required to manage the game Upon instantiation of a game, set up the list of players (use 4 players for your demo/sample data), create the deck, shuffle and deal 3 cards to each player. Begin the game with the first player in the list. Each player will have their turn when positioned at the head of the list. Notes: - Use enhanced enums to set the value for a face card. Mark special cards through this value. If the player plays an ACE, play 11 unless it will cause them to lose the round. When faced with possibly going over 99, the player should play a card that prevents them from losing. Otherwise any card can be played. Note in the sample output below, the first card in the hand is played. To format output, include a String field display and override the enum's toString(). Use unicode values \u2663, \u2660, \u2665, \u2666 for clubs, spades, hearts and diamonds respectively. Sample output: Let's play 99!!! Players: Simba, Nala, Timon, Pumbaa 6 (Simba's hand: 104, Simba plays 104 The total is -10 (Nala's hand: A+, 2, 5) Nala plays Ad The total is 1 (Timon's hand: 44, 4., 5.) Timon plays 44 Game reverses direction (Nala's hand: 2, 5, K) Nala plays 2 The total is 3 (Simba's hand: 69, Q., K.) Simba plays 6 The total is 9 (Pumbaa's hand: 104, 9, 8) Pumbaa plays 10% The total is -1 (Timon's hand: 4., 5., 9) Timon plays 4. Game reverses direction 3 . (Pumbaa's hand: 9, Pumbaa plays 9. Simba skips a turn (Nala's hand: 5, K, 54) Nala plays 5 The total is 4 34) (Timon's hand: 5., 9 Timon plays 5. The total is 9 (Pumbaa's hand: 8., Pumbaa plays 8. The total is 17 (Simba's hand: g., K., 3) Simba plays Q The total is 27 (Nala's hand: K, 54, 34) Nala plays K The total is 99 (Timon's hand: 9, 34, 3.) Timon plays 9 Pumbaa skips a turn (Simba's hand: K., 3, 10) Simba plays K The total is 99 (Nala's hand: 5, 39, 2) Nala plays 5 The total is 104 Nala loses this round PART B: Stacks (30 marks) Create a program that simulates the undo/redo features of an application. Implement a simple calculator that asks the user for the basic arithmetic operation that they would like to perform on the last result. Your program will: Prompt the user to enter an initial number (first operand) Then prompt the user for the next operator and second operand evaluate the expression present the user with the result, which will be the new first operand This will continue until the user chooses to quit, or undo (redo) an operation The undo operation restores the last state. The redo operation restores the next state if an undo was previously performed. 1. Create the generic ArrayStack that implements the Stack interface using an array. 2. Create a driver class called As 1Parts_Driver and any other classes/methods that you may require. You must use two stack objects to hold items that will restore the states based on the function (undo "z" or redo "y") selected. Allow the user to quit ("q") anytime. Sample output: Simple Calculator: type z to undo, y to redo, q to quit Enter the first number: 10 Enter the next operation on 10: + 2 = 12 Enter the next operation on 12: - 3 = 9 Enter the next operation on 9: Z UNDO: 12 Enter the next operation on 12: z UNDO: 10 Enter the next operation on 10: 10 = 100 Enter the next operation on 100: / 5 = 20 Enter the next operation on 20: + 4 = 24 Enter the next operation on 24: z UNDO: 20 Enter the next operation on 20: Z UNDO: 100 Enter the next operation on 100: REDO: 20 Enter the next operation on 20: y REDO: 24 Enter the next operation on 24: y Nothing to redo. Enter the next operation on 24: + 6 = 30 Enter the next operation on 30: z UNDO: 24 Enter the next operation on 24: Z UNDO: 20 Enter the next operation on 20: z UNDO: 100 Enter the next operation on 100: z UNDO: 10 Enter the next operation on 10: z Nothing to undo. Enter a number: 12 Enter the next operation on 12: 9 Goodbye

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_2

Step: 3

blur-text-image_3

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

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago