es ist zwar nichts zum Webprogrammierung, aber trotzdem Programmierung mittels Java.
Also AUfgabe ist es im Prinzip die Klasse Card zu erstellen, unter anderem soll die Methode toString() überschrieben werden, jedoch funktioniert das nicht so, wie ich mir das hier vorstelle, könnte ihr mir helfen?
Ich bekomme immer die Meldung das die Methode einen Wert vom Typ String zurückgeben muss, eigentlich sollte sie dies ja auch tun, jedoch passiert nichts.
Code: Alles auswählen
public class Card {
enum Type {KREUZ, PIK, HERZ, KARO};
enum Value {Ass, b,c,d,e,f,g,h,i,j,Bube,Dame, König};
private Type cardType;
private Value cardValue;
Card (){
this.cardType = Type.KREUZ;
this.cardValue = Value.b;
}
Card (Type cardType, Value cardValue){
this.cardType = cardType;
this.cardValue = cardValue;
}
public Type getType(){
return cardType;
}
public Value getValue(){
return cardValue;
}
public String toString() {
switch (this.cardType) {
case KREUZ: return "Kreuz";
case PIK: return "Pik";
case HERZ: return "Herz";
case KARO: return "Karo";
}
}
public static void main(String[] args)
{
Card a = new Card(Type.HERZ, Value.b);
a.toString();
}
}