Donate SIGN UP

Java Programme

Avatar Image
AutomaticGal | 22:58 Sat 01st Dec 2007 | How it Works
3 Answers
Im making a programme for my assignment which takes in user input via a JOptionPane inputbox. the programme should take the user input and give a diagalogue back.

for example for a deck of cards user types A. the program should return Ace, K - King, J - Jack, Q - Queen 2..10 should return two-ten etc

ive got it to recognise the numbers as ive converted the String into datatype int. and used the if statement e.g

if(input == 2)
System.out.println(''Two'');

but i dont know how i can get it to recognize Letters and return words... can anyone help?
Gravatar

Answers

1 to 3 of 3rss feed

Best Answer

No best answer has yet been selected by AutomaticGal. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
Ashamed to say I can't remember offhand, but try the same text but putting the letters (capital and lowercase) in parentheses also.
Question Author
tried that it doesnt work...... :-(

ive tried changing the datatype to char but as im using JOptionPane it doesnt recognize it. ive added a line afterwards to change the string input to an int but i have given the int another name. look


Cards()
{
input1 = JOptionPane.showInputDialog("Enter Character corisponding to card value:");
num1 = Integer.parseInt(input1);

if (num1 == 2)
System.out.println("Two");

if(input1 == "A")
if(input1 == "a")
System.out.println("ace")



ive also tried .= != tried initializing the String out of the constructor... im stuckkkkkkkkkkkk
Try a switch statement:

switch input;
{
case "a": //if input ==a
doSomethingHere;
break;
case "b": //if input ==b
doSomethingHere;
break;
}

You can also do this:
switch input;
{
case "a", case "b": //same as if input == a or b
doSomethingHere;
break;
}

http://www.cafeaulait.org/course/week2/42.html


1 to 3 of 3rss feed

Do you know the answer?

Java Programme

Answer Question >>