Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Date:2014.10.08
- * @author LinChuWen
- * NCHU EE,course number:2335
- * course name:Object Oriented Language
- *
- * Textbook:Big Java: Late Objects - Cay S. Horstmann
- * Problem:P3.14
- */
- import java.util.*;
- public class HW2_P3_14 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String card;
- char suit,number;
- int length;
- try{
- System.out.print("Enter the card notation: ");
- card = input.nextLine();
- length = card.length();
- number = card.charAt(length-2);
- suit = card.charAt(length-1);
- switch(number){
- case 'A':case 'a':
- System.out.print("Ace of ");
- break;
- case '2':
- System.out.print("Two of ");
- break;
- case '3':
- System.out.print("Three of ");
- break;
- case '4':
- System.out.print("Four of ");
- break;
- case '5':
- System.out.print("Five of ");
- break;
- case '6':
- System.out.print("Six of ");
- break;
- case '7':
- System.out.print("Seven of ");
- break;
- case '8':
- System.out.print("Eight of ");
- break;
- case '9':
- System.out.print("Nine of ");
- break;
- case '0':
- System.out.print("Ten of ");
- break;
- case 'J':case 'j':
- System.out.print("Jack of ");
- break;
- case 'Q':case 'q':
- System.out.print("Queen of ");
- break;
- case 'K':case 'k':
- System.out.print("King of ");
- break;
- } //switch(number) end
- switch(suit){
- case 'C':case 'c':
- System.out.println("Clubs");
- break;
- case 'D':case 'd':
- System.out.println("Diamonds");
- break;
- case 'H':case 'h':
- System.out.println("Hearts");
- break;
- case 'S':case 's':
- System.out.println("Spades");
- break;
- } //switch(suit) end
- } //try end
- catch(Exception ex){
- System.out.println("Wrong Input!");
- } //catch end
- finally{
- input.close();
- } //finally end
- } //main end
- } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement