Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java, for the final project you will be creating an automated version of the classic card game WAR, using classes and objects. Create the
In Java, for the final project you will be creating an automated version of the classic card game WAR, using classes and objects. Create the following classes:
a Card
i Fields
value contains a value from representing cards Ace
name eg Ace of Diamonds, or Two of Hearts
ii Methods
Getters and Setters
describe prints out information about a card
b Deck
i Fields
cards List of Card
ii Methods
shuffle randomizes the order of the cards
draw removes and returns the top card of the Cards field
In the constructor, when a new Deck is instantiated, the Cards field should be populated with the standard cards.
c Player
i Fields
hand List of Card
score set to in the constructor
name
ii Methods
describe prints out information about the player and calls the describe method for each card in the Hand List
flip removes and returns the top card of the Hand
draw takes a Deck as an argument and calls the draw method on the deck, adding the returned Card to the hand field
incrementScore adds to the Players score field
Create a class called App with a main method.
a Instantiate a Deck and two Players, call the shuffle method on the deck.
b Using a traditional for loop, iterate times calling the Draw method on the other player each iteration using the Deck you instantiated.
c Using a traditional for loop, iterate times and call the flip method for each player.
Compare the value of each card returned by the two players flip methods. Call the incrementScore method on the player whose card has the higher value. Print a message to say which player received a point.
Note: If the values are equal it is a tie print a message saying that no point was awarded.
d After the loop, compare the final score from each player.
e Print the final score of each player and either Player Player or Draw depending on which score is higher or if they are both the same.
Tips: Printing out information throughout the game adds value including easier debugging as you progress and a better user experience.
a Using the Card describe method when each card is flipped illustrates the game play.
b Printing the winner of each turn adds interest or a message indicating a tie.
c Printing the updated score after each turn shows game progression.
d At the end of the game: print the final score of each player and the winners name or Draw if the result is a tie.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started