Advertisement
calcpage

C5X2_Card.java

Nov 16th, 2011
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. public class Card
  2. {
  3.     private String face;
  4.     private String suit;
  5.  
  6.     /**
  7.     Constructor: splits up input
  8.     @param card input from commandline
  9.     */
  10.     public Card(String card)
  11.     {
  12.         //what about lowercase or mixed input?
  13.         if(card.length()==2)
  14.         {
  15.             face = card.substring(0,1);
  16.             suit = card.substring(1,2);
  17.         }
  18.         else
  19.         {
  20.             face = card.substring(0,2);
  21.             suit = card.substring(2,3);
  22.         }
  23.     }
  24.  
  25.     /**
  26.     Accessor: parses up input
  27.     @return "face" of "suit"
  28.     */
  29.     public String getDescription()
  30.     {
  31.         String temp = "";
  32.         if(face.equals("2")){temp+="Two";}
  33.         if(face.equals("3")){temp+="Three";}
  34.         if(face.equals("4")){temp+="Four";}
  35.         if(face.equals("5")){temp+="Five";}
  36.         if(face.equals("6")){temp+="Six";}
  37.         if(face.equals("7")){temp+="Seven";}
  38.         if(face.equals("8")){temp+="Eight";}
  39.         if(face.equals("9")){temp+="Nine";}
  40.         if(face.equals("10")){temp+="Ten";}
  41.         if(face.equals("J")){temp+="Jack";}
  42.         if(face.equals("Q")){temp+="Queen";}
  43.         if(face.equals("K")){temp+="King";}
  44.         if(face.equals("A")){temp+="Ace";}
  45.         if(suit.equals("H")){temp+=" of Hearts";}
  46.         if(suit.equals("D")){temp+=" of Diamonds";}
  47.         if(suit.equals("C")){temp+=" of Clubs";}
  48.         if(suit.equals("S")){temp+=" of Spades";}
  49.         return temp;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement