I got dinged points for these:
Instructor wants 1. The class is divided into multiple methods, mentioned a Constructor instead? 2. The toString method is included in the Card class to return the face and suit.
What did I do wrong? How do I fix it? I am pretty lost and don't know where to even start...
import java.util.Random;
public class Card
{
public String cardGeneration()
{
Random generator = new Random();
int x; // random integer representing suit
int y; // random integer for card value
String mysuit, mynumber; //assigning names, these will be changed
int suits = 4, numbers = 13; //depending what card is picked
x = generator.nextInt(suits); // random integer between 0 & 3 inclusive
if (x == 0)
mysuit = "Clubs";
else if (x == 1)
mysuit = "Diamonds";
else if (x == 2)
mysuit = "Hearts";
else if (x == 3)
mysuit = "Spades";
else
mysuit = "NA";
y = generator.nextInt(numbers) + 1; // add 1 so that y is between 1 & 13 inclusive
if (y == 1)
mynumber = "Ace";
else if (y == 2)
mynumber = "Two";
else if (y == 3)
mynumber = "Three";
else if (y == 4)
mynumber = "Four";
else if (y == 5)
mynumber = "Five";
else if (y == 6)
mynumber = "Six";
else if (y == 7)
mynumber = "Seven";
else if (y == 8)
mynumber = "Eight";
else if (y == 9)
mynumber = "Nine";
else if (y == 10)
mynumber = "Ten";
else if (y == 11)
mynumber = "Jack";
else if (y == 12)
mynumber = "Queen";
else if (y == 13)
mynumber = "King";
else
mynumber = "NA";
String result = mynumber + " of " + mysuit;
return result;
}
}
Thanks!