所以基本上对于我的计算机科学课,我们必须创建一个 Card 类,它接受用户输入的卡片符号(例如“4S”)并有一个 getDescription 方法返回卡片的描述(“黑桃四”)。问题是,关于 if 语句,我不断收到“无法访问的语句”错误。我可能做错了整件事,但这是我所做的:
import java.util.Scanner;
public class Card
{
private String face;
private String suit;
public Card()
{
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();
}
}