Computing.Net > Forums > Programming > Need help with a Java Program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need help with a Java Program

Reply to Message Icon

Name: hymn7
Date: March 16, 2005 at 14:14:34 Pacific
OS: XP
CPU/Ram: 512 MB
Comment:

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..



Sponsored Link
Ads by Google

Response Number 1
Name: dsbInspiron
Date: March 17, 2005 at 09:01:19 Pacific
Reply:

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.


0

Response Number 2
Name: hymn7
Date: March 17, 2005 at 17:27:28 Pacific
Reply:

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


0

Response Number 3
Name: dsbInspiron
Date: March 18, 2005 at 05:25:53 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need help with a Java Program

Need help with C++? www.computing.net/answers/programming/need-help-with-c/4642.html

Need help with loop...... www.computing.net/answers/programming/need-help-with-loop/5937.html

I need Help explaining a C program www.computing.net/answers/programming/i-need-help-explaining-a-c-program/17576.html