The problem is that the first character read here:
char ch = (char) br.read();
... won't be available until you've hit return, at which point you've got an empty line.
If you run your code and type
dSomeone
(and then hit return) then you'll get a name of "Someone" to try to delete.
The simplest approach would probably be to use:
String option = br.readLine();
if (option == null) {
// User has basically terminated stdin. Die somehow
}
if (option.equalsIgnoreCase("D")) {
String name = br.readLine();
...
}
Also note that this code isn't useful:
String empName = br.readLine();
deleteElement();
You're asking for a name, but then ignoring it. How is deleteElement
meant to know which employee you want to delete? You should probably make the name a parameter to the method, and supply it when calling:
String empName = br.readLine();
deleteElement(empName);