My Current Card Class
public class Card
{
private String suit;
private int value;
public void setSuit(String newSuit) //Setting suit
{
suit = newSuit;
}
public String getSuit() //Getting suit
{
return suit;
}
public void setValue(int newValue) //Setting value
{
value = newValue;
}
public int getValue() //Getting value
{
return value;
}
}
My Current War2 Class
public class War2
{
public static void main(String[] args)
{
int myValue, myValue1, mySuit1, mySuit2;
Card myCard = new Card();
Card myCard2 = new Card();
final int CARDS_SUIT = 4;
mySuit1 = ((int)(Math.random() * 100) % CARDS_SUIT + 1); //Generating random number for 1st Card Suit
if (mySuit1 == 1) //Nested if to set random suit to 1st Card
myCard.setSuit("Spades"); //Setting setSuit in the Card Class
else
if (mySuit1 == 2)
myCard.setSuit("Hearts");
else
if (mySuit1 == 3)
myCard.setSuit("Diamond");
else
if (mySuit1 == 4)
myCard.setSuit("Clubs");
final int CARDS_SUIT1 = 4;
mySuit2 = ((int)(Math.random() * 100) % CARDS_SUIT1 + 1); //Generating random number for 2nd Card Suit
if (mySuit2 == 1) //Nested if to set random suit to 2nd Card
myCard2.setSuit("Spades"); //Setting setSuit in the Card Class
else
if (mySuit2 == 2)
myCard2.setSuit("Hearts");
else
if (mySuit2 == 3)
myCard2.setSuit("Diamond");
else
if (mySuit2 == 4)
myCard2.setSuit("Clubs");
final int CARDS_IN_SUIT = 13;
myValue = ((int)(Math.random() * 100) % CARDS_IN_SUIT + 1); //Generating random number for cards
myValue1 = ((int)(Math.random() * 100) % CARDS_IN_SUIT + 1);
myCard.setValue(myValue);
myCard2.setValue(myValue1);
System.out.println("My Card is the " + myCard.getValue() + " of " + myCard.getSuit()); //Displaying Card Details
System.out.println("Your Card is the " + myCard2.getValue() + " of " + myCard2.getSuit());
if (myCard.getValue() > myCard2.getValue()) //Nested if to display Winner or Tie
System.out.println("I win");
if (myCard.getValue() < myCard2.getValue())
System.out.println("You win");
else if (myCard.getValue() == myCard2.getValue())
System.out.println("Its a tie");
}
}
My Current Output
My Card is the 4 of Spades
Your Card is the 13 of Clubs
You win
My Current Problem
I am trying to get within the Card class setValue() method, besides
setting the numeric value, also set the string rank value as follows.
Assuming Ace is the lowest value.
Numeric value String value for rank
1 “Ace”
2 through 10 “2” through “10”
11 “Jack”
12 “Queen”
13 “King”
And achieve an outcome like this :
My Card is the Ace of Spades
Your Card is the 2 of Clubs
You win
Can I please get an idea of how to go about it. Confused