right I am trying to practice with my programming taking my lectures advice and breaking the problem down into steps, then when I code, code a small amount, compile it check it works and then code the next bit. So I have an exercise I am trying out. Part of what I need to do I am not sure of. I know I have to convert an int to a string but I am not sure which one.
Card.Java
This is a simple class that represents a playing card.-rank: String
-suit: String
+card(int,String)
+getSuit(): String
+getRank(): String
Card has two attributes: rank which is a String that represents the value of a card. It takes the values “ACE,”2”,”3”,…,”JACK”,”QUEEN”,”KING”; suit a String which takes the values “SPADES”,”DIAMONDS”,”CLUBS”,”HEARTS”.The class has a single constructor which takes two parameters: the first is an int that represents the rank in the range 1 to 13; the second a String representing the suit. The constructor must convert the int into an appropriate String value.
Additionally there are two methods that return String representations of the suit and rank respectively.
here is what I have planned
I need 2 arrays 1 for suit and 1 for rank which should contain all the card types numbers on cards and suits.
converting an int to a string can be done using toString. however I am not sure what String I am converting the int 2 I think it is converting it to rank but I am not sure. The int seems to me to be representative of the rank.
So I have basic code looking something like this
public class Card
{
getSuit();
getRank();
publlic Card(int rankNum, String suit)
{
for (int i=1; i<14; i++)
{
rank = Integer.toString(i);
}
}
public String getSuit()
{
String suit [4]={"spades","hearts","diamonds","clubs"};
return suit;
}
public String getRank()
{
String suit [13]={"ACE","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
return rank;
}
The biggest problem I have is that this seems only possible using arrays but the problem has suit and rank not as arrays but needs to be able to take those values. I am seriously confused. Any correction on my planning would be much appreciated particularly with the bit i highlighted in bold.