Question: Write a Java program that sets up the basics for playing a simple version of the card game War. You will enhance this program in

Write a Java program that sets up the basics for playing a simple version of the card game War. You will enhance this program in future assignments. The requirements for this assignment are as follows:
For now, the program should start with a basic startup class (PlayGame) with a main entry point that runs the procedural steps for your card game. It will create two instances of another class (Card) that represents a playing card.
The Card class must keep track of its rank (1 through 13) and suit (0 through 3) as private integer member variables. This is important! All member variables throughout the semester must be made explicitly private (except constants)!
In the Card class, create an accessor function to get the rank value. Name it getRank.
The Card class must also have a member function to draw the card. For the time being, drawing a card will simply set the rank and suit member variables by generating random numbers from 1 to 13 and 0 to 4 and storing the results. Eventually, we will use this class properly to create and manage a full deck of cards. Name this function drawCard.
This class must also override the toString function (available to all objects) so that the program can directly print the rank and suit of a Card object (e.g. "Four of Spades"). It will be necessary to map the member variable integers to appropriate strings. It is probably easiest to do this with two parallel arrays of (constant) String variables.
Your game, for now, will create two instances of the Card object, one for each player. For each turn, simply call the drawCard function for each player from the two existing card objects. This does not simulate a proper deck (the may be duplicates and repititions), but it is good enough for our purposes for now.
Run the game by looping through four turns in the procedural main function.
For each turn the program must draw a card for each player and output the results. It must also determine output the winner per turn, based on rank. Ignore the suit for now.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!