Created
November 12, 2008 07:52
-
-
Save danahern/24107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JOptionPane; | |
public class cards | |
{ | |
public static void main(String[] args) | |
{ | |
String input; | |
String typeofcard = "......."; | |
String valueofcard = "....."; | |
int picture=0; | |
char[] chararray = new char[5]; | |
do | |
{ | |
//int counter = 1; | |
//if(counter == 1) | |
input = JOptionPane.showInputDialog("Please enter the short hand for your card"); | |
//else | |
// input = JOptionPane.showInputDialog("Your first input was incorrect please enter the correct short hand for your card"); | |
chararray = input.toCharArray(); | |
for (int i = 0; i<chararray.length; i++) | |
{ | |
if(chararray[i] == 'd'||chararray[i] == 'D') | |
{ | |
typeofcard = "Diamonds"; | |
picture = 4; | |
} | |
else if(chararray[i] == 's'||chararray[i] == 'S') | |
{ | |
typeofcard = "Spades"; | |
picture = 6; | |
} | |
else if(chararray[i] == 'h'||chararray[i] == 'H') | |
{ | |
typeofcard = "Hearts"; | |
picture = 3; | |
} | |
else if(chararray[i] == 'c'||chararray[i] == 'C') | |
{ | |
typeofcard = "Clubs"; | |
picture = 5; | |
} | |
} | |
for(int i=0;i<chararray.length;i++) | |
{ | |
if(chararray[i] == 'a' || chararray[i] == 'A') | |
{ | |
valueofcard = "Ace"; | |
} | |
else if(chararray[i] == 'k' || chararray[i] == 'K') | |
{ | |
valueofcard = "King"; | |
} | |
else if(chararray[i] == 'q' || chararray[i] == 'Q') | |
{ | |
valueofcard = "Queen"; | |
} | |
else if(chararray[i] == 'j' || chararray[i] == 'J') | |
{ | |
valueofcard = "Jack"; | |
} | |
else if(Character.isDigit(chararray[i]) && chararray[i] != '0') | |
{ | |
if(chararray[i] == '1' && chararray[i+1] == '0') | |
{ | |
valueofcard = "10"; | |
System.out.println(valueofcard); | |
} | |
else if(chararray[i] != 0 || chararray[i] != 1) | |
{ | |
char temp; | |
temp = chararray[i]; | |
System.out.println(temp); | |
valueofcard = Character.toString(temp); | |
} | |
} | |
} | |
// counter++; | |
}while(typeofcard == "......." || valueofcard == "....."); | |
System.out.print("The short hand that you inputed indicated that you have the " +valueofcard +" of " +typeofcard +" " +(char)picture); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment