Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint Message if HashMap name is Emply
    primarykey
    data
    text
    <p>I have a program that when you type </p> <blockquote> <p>Circle name</p> </blockquote> <p>in the Terminal, "name" goes into the HashMap then later I can type </p> <blockquote> <p>name visible</p> </blockquote> <p>and the circle will appear on a canvas, or </p> <blockquote> <p>name invisible</p> </blockquote> <p>and will then disappear. I'm using if else statement to call methods. I also created a statement called forget so When I type in </p> <blockquote> <p>name forget</p> </blockquote> <p>it will remove "name" out of the HashMap then make the circle invisible if the circle is visible.</p> <pre><code>private void execute(String[] commands) { String basicCommand = commands[0]; Shape name = maps.get(commands[0]); if (commands.length &gt;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 &amp;&amp; "visible".equals(commands[1])) { makeACircle(name); } else if(name != null &amp;&amp; "forget".equals(commands[1])) { makeItInvisible(name); maps.remove(commands[0]); } else if(name != null &amp;&amp; "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); } } </code></pre> <p>}</p> <p>If I use </p> <blockquote> <p>name forget</p> </blockquote> <p>It will remove name from the HashMap</p> <p>I need it to print a message when "name" is not in the HashMap if you type something "name visible", I need a message that print something like "not in HashMap" .</p> <p>I tried it withing my if else statement, but anything below it does not work, and can't get it to work</p> <p><img src="https://i.stack.imgur.com/29orT.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload