0
所以基本上對於我的計算機科學課,我們必須創建一個Card類,它爲用戶輸入卡片符號(例如「4S」)並且具有getDescription方法,該方法返回卡片的描述(「四個黑桃」) 。問題是,我不斷收到有關if語句的「無法訪問的語句」錯誤。我大概做了整個事情錯了,但這裏是我做過什麼:如何在java中做這個卡類?
import java.util.Scanner;
public class Card
{
private String face;
private String suit;
public Card()
{ \t
Scanner card = new Scanner(System.in);
System.out.print("Enter the card notation: ");
String input = card.next();
face = input.substring(0,1);
suit = input.substring(1);
}
public String getDescription()
{
return "Your card was the ";
if (face.equals("A")) return "ace";
return getDescription();
}
}