Advertisement
Go-Ice

Sophomore Java Homework-P3.14

Oct 7th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. /**
  2.  * Date:2014.10.08
  3.  * @author LinChuWen
  4.  * NCHU EE,course number:2335
  5.  * course name:Object Oriented Language
  6.  *
  7.  * Textbook:Big Java: Late Objects - Cay S. Horstmann
  8.  * Problem:P3.14
  9.  */
  10. import java.util.*;
  11. public class HW2_P3_14 {
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner input = new Scanner(System.in);
  15.         String card;
  16.         char suit,number;
  17.         int length;
  18.        
  19.         try{
  20.             System.out.print("Enter the card notation: ");
  21.             card = input.nextLine();
  22.            
  23.             length = card.length();
  24.             number = card.charAt(length-2);
  25.             suit = card.charAt(length-1);
  26.            
  27.             switch(number){
  28.                 case 'A':case 'a':
  29.                     System.out.print("Ace of ");
  30.                     break;
  31.                 case '2':
  32.                     System.out.print("Two of ");
  33.                     break;
  34.                 case '3':
  35.                     System.out.print("Three of ");
  36.                     break;
  37.                 case '4':
  38.                     System.out.print("Four of ");
  39.                     break;
  40.                 case '5':
  41.                     System.out.print("Five of ");
  42.                     break;
  43.                 case '6':
  44.                     System.out.print("Six of ");
  45.                     break;
  46.                 case '7':
  47.                     System.out.print("Seven of ");
  48.                     break;
  49.                 case '8':
  50.                     System.out.print("Eight of ");
  51.                     break;
  52.                 case '9':
  53.                     System.out.print("Nine of ");
  54.                     break;
  55.                 case '0':
  56.                     System.out.print("Ten of ");
  57.                     break;
  58.                 case 'J':case 'j':
  59.                     System.out.print("Jack of ");
  60.                     break;
  61.                 case 'Q':case 'q':
  62.                     System.out.print("Queen of ");
  63.                     break;
  64.                 case 'K':case 'k':
  65.                     System.out.print("King of ");
  66.                     break;
  67.             } //switch(number) end
  68.            
  69.             switch(suit){
  70.                 case 'C':case 'c':
  71.                     System.out.println("Clubs");
  72.                     break;
  73.                 case 'D':case 'd':
  74.                     System.out.println("Diamonds");
  75.                     break;
  76.                 case 'H':case 'h':
  77.                     System.out.println("Hearts");
  78.                     break;
  79.                 case 'S':case 's':
  80.                     System.out.println("Spades");
  81.                     break;
  82.             } //switch(suit) end
  83.         } //try end
  84.        
  85.         catch(Exception ex){
  86.             System.out.println("Wrong Input!");
  87.         } //catch end
  88.        
  89.         finally{
  90.             input.close();
  91.         } //finally end
  92.     } //main end
  93. } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement