The directions for the assignment are: Program a game of War. In War, if the value of your card is greater than your opponent's card, you earn one point. If your opponent's card is greater than your card, your opponent gets a point. If you tie it is a war! That means the next hand is worth 2 points. If it is another tie, then the next hand is worth 4 points, and you keep adding 2 until the tie is broken. Then the scoring goes back to normal.
1) You should use your Cards class to get 2 playing cards.
2) Ask the user how many rounds they would like to play.
3) Have a loop to catch if they enter a negative number of rounds.
4) End the program if they want to play 0 rounds.
5) Print the user's car and the computer's card for each round.
6) Print out the correct score after each round.
7) Aces are LOW (Worth 1 point).
8) After all the rounds are complete, print a message that tells the user if they won, lost, or tied.
I have the driver class ready (see below). I need help creating a class that will do the stuff stated above. After each round it should ask the user to press enter to go on to the next round. Here is my driver class code, it provides a card number and suit.
public class Cards
{
private int A;
private int B;
private String c;
private String b;
public Cards()
{
getSuit();
getCardName();
suit();
name();
}
public int getSuit()
{
A = (int) (Math.random()*4+1); //rolls a number between 1 and 4
return A;
}
public int getCardName()
{
B = (int) (Math.random()*13+1); //rolls a number between 1 and 13
return B;
}
public String suit()
{
if (A == 1) b = "Hearts";
else if (A == 2) b = "Diamonds";
else if (A == 3) b = "Clubs";
else b = "Spades";
return b;
}
public String name()
{
if (B == 1) c = "Ace";
else if (B == 2) c = "2";
else if (B == 3) c = "3";
else if (B == 4) c = "4";
else if (B == 5) c = "5";
else if (B == 6) c = "6";
else if (B == 7) c = "7";
else if (B == 8) c = "8";
else if (B == 9) c = "9";
else if (B == 10) c = "10";
else if (B == 11) c = "Jack";
else if (B == 12) c = "Queen";
else c = "King";
return c;
}
public String toString()
{
return c + " of " + b;
}
}