私はあなたが入力したときにプログラムを持っています
サークル名
ターミナルでは、「名前」が HashMap に入り、後で入力できます
名前が見える
円がキャンバスに表示されるか、または
名前が見えない
そして消えていきます。if else ステートメントを使用してメソッドを呼び出しています。Forget soというステートメントも作成しました
名前忘れ
HashMap から「名前」を削除し、円が表示されている場合は円を非表示にします。
private void execute(String[] commands)
{
String basicCommand = commands[0];
Shape name = maps.get(commands[0]);
if (commands.length >1) {
if(basicCommand.equals("circle")) {
//This Names the object Circle and Create a new Circle
maps.put(commands[1], new Circle());
}
else if(name != null && "visible".equals(commands[1])) {
makeACircle(name);
}
else if(name != null && "forget".equals(commands[1])) {
makeItInvisible(name);
maps.remove(commands[0]);
}
else if(name != null && "invisible".equals(commands[1])) {
makeItInvisible(name);
}
else if(basicCommand.equals("help")) {
printHelp();
}
//This Should Print A Message if there is no Circle name
// in HashMap
else if(commands[0] != null ) {
System.out.println("Not In HashMap " + basicCommand);
}
else {
System.out.println("Unknown command: " + basicCommand);
}
}
}
私が使用する場合
名前忘れ
HashMap から名前を削除します
「name visible」と入力すると、「name」が HashMap にないときにメッセージを出力する必要があります。「not in HashMap」のようなメッセージを出力する必要があります。
if else ステートメントで試してみましたが、それ以下は機能せず、機能しません