Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I've had the Flu for a while, and was absent from school, so I'm behind in my Java class. I'm stuck at this one program, and I cant figure it out, and don't want to waste time on it.. Can someone help? I'm only in Java 1, so it's nothing to big, I don't think..
We just started learning about keyboard input to the programs, and we're suppose to make a card program where we type something like "5D" and it prints out "Five of Diamonds".
I have to have to use constructors (Which I'm terrible at) and using Strings for info for 1-10, Ace, Jack, Queen, King, Spades, Diamonds, Hearts, and Clubs. The string info has to be in my Cards.java, and calling it suppose to be in TestCards.java.
I don't have my program right here with me, but I don't really have anything, except errors..
I have the string set up, and I have it where I can type stuff in.. but I've spent all day trying to call the string data over from Card.java to TestCard.java.. It doesn't make since.
I'm not really asking for anyone to write it (though I'd gladlly accept it if someone did, lol) but to explain to me how it's done..

I assume Cards.java has been created. I don't follow the exact instructions, but it seems that you pass into the Constructor the type of card (i.e. "5D). Create the Constructor. Card(string cardName)
{
someVar = cardName;
}
Note the constructors name must be the same name as the Class (public class Card <-). Now in testCard.java you would call this constructor like this... Card cVariable = new Card(stringVariable). I hope this gets you started, I will write some more if you need help but not the whole thing, feel free to write back if you need more assistance.

Yeah, I have it that far. The Main thing I'm having trouble with is How to take input from Cards.java to pull a string from TestCards.java

I am not sure I follow you. Are you saying that you have already converted the string to its final form (Five of Diamonds) and need to return it back to the calling program to printed to the screen? I am also wondering, did you write a function that would do the converting? If so, just write return the "Five of Diamonds in a variable. return strVar; at the end...so in testCard.java, you could just set a string var equal to this function.
Card cd = new Card(strSymbol);
string fullName = cd.Convert();
System.out.println(fullName);Maybe if you could, you put what code you have and that would make it easier to help, if not advise a little clearer on what you actually need.
db

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |