[SOLVED] Intro to Java Week 6 Coding Assignment

30.00 $

Category:

Description

Rate this product

For the final project you will be creating an automated version of the classic card game WAR.

  1. Create the following classes:
  2. Card
  3. Fields
  4. value (contains a value from 2-14 representing cards 2-Ace)
  5. name (e.g. Ace of Diamonds, or Two of Hearts)
  6. Methods
  7. Getters and Setters
  8. describe (prints out information about a card)
  9. Deck
  10. Fields
  11. cards (List of Card)
  12. Methods
  13. shuffle (randomizes the order of the cards)
  14. draw (removes and returns the top card of the Cards field)
  15. In the constructor, when a new Deck is instantiated, the Cards field should be

populated with the standard 52 cards.

  1. Player
  2. Fields
  3. hand (List of Card)
  4. score (set to 0 in the constructor)
  5. name
  6. Methods
  7. describe (prints out information about the player and calls the describe method

for each card in the Hand List)

  1. flip (removes and returns the top card of the Hand)
  2. draw (takes a Deck as an argument and calls the draw method on the deck,

adding the returned Card to the hand field)

  1. incrementScore (adds 1 to the Player’s score field)

Page 2 of 3Intro to Java Week 6 Coding Assignment

  1. Create a class called App with a main method.
  2. a) Instantiate a Deck and two Players, call the shuffle method on the deck.
  3. b) Using a traditional for loop, iterate 52 times calling the Draw method on the other player each

iteration using the Deck you instantiated.

  1. c) Using a traditional for loop, iterate 26 times and call the flip method for each player.
  2. d) Compare the value of each card returned by the two player’s flip methods. Call the

incrementScore method on the player whose card has the higher value.

  1. e) After the loop, compare the final score from each player.
  2. f) Print the final score of each player and either “Player 1”, “Player 2”, or “Draw” depending on

which score is higher or if they are both the same.

  1. Tips: Printing out information throughout the game adds value including easier debugging as you progress

and a better user experience.

  1. a) Using the Card describe() method when each card is flipped illustrates the game play.
  2. b) Printing the winner of each turn adds interest.
  3. c) Printing the updated score after each turn shows game progression.
  4. d) At the end of the game: print the final score of each player and the winner’s name or “Draw” if the

result is a tie.