Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: Java  |  size: 0.86 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. public class Karte {
  2.        
  3.         public final static int KARO = 0, HERZ = 1, PIK = 2, KREUZ = 3;
  4.         private final int farbe, wert;
  5.         private final String typ;
  6.        
  7.         public Karte(int f, int w, String a){
  8.                 farbe = f;
  9.                 wert = w;
  10.                 typ = a;
  11.         }
  12.        
  13.         public int getWert(){
  14.                 return wert;
  15.         };
  16.        
  17.         public int getFarbe(){
  18.                 return farbe;
  19.         };
  20.        
  21.         public String getTyp(){
  22.                 return typ;
  23.         };
  24.        
  25.         public String toString(){
  26.                 if (getTyp().startsWith("Z")) return farbe2String() + " " + wert + " " + typ2String();
  27.                 else return farbe2String() + " " + typ2String();
  28.         }
  29.        
  30.         public String farbe2String(){
  31.                 switch(farbe){
  32.                 case KARO:
  33.                         return "Karo";
  34.                 case HERZ:
  35.                         return "Herz";
  36.                 case PIK:
  37.                         return "Pik";
  38.                 case KREUZ:
  39.                         return "Kreuz";
  40.                 }
  41.         return "-1";
  42.         }
  43.        
  44.         public String typ2String(){
  45.                 if (getTyp().startsWith("Z")) return "";       
  46.                 else return getTyp();
  47.                 }
  48. }