boolean deleteRange() { // handle empty list if ( profs.size() == 0 ) { System.out.println("\n The list contains " + profs.size() + " elements.\n"); // handle non-empty list } else if (profs.size() == 1) { System.out.println("\n The list contains " + profs.size() + " element.\n" + " Reversal on " + profs.size() + " item is not possible. Add more elements.\n"); // handle larger than one element list } else { // for easier readability int size = profs.size(); // present the list for viewing handlePrintList(); System.out.println("\nInput range of professors to " + " delete(ex: 4<enter>, 7<enter>, " + "\ndeletes professors 4,5,6,7), or 0 to quit)."); // required variables int choice = 0; // default initialization to zero before the try/catch int choiceTwo = 0; // topmost range choice System.out.print("First professor: "); // first choice to get String entryOne = jmhUtilities.ReadLine(); // read user input // prevent invalid input of non-numeric type try { choice = Integer.parseInt(entryOne); // get first character } catch(NumberFormatException nfe) { System.out.println("\n Invalid input of non-numeric type." + "\n Enter an integer between 1 and " + size + " next time.\n"); return true; } catch (IndexOutOfBoundsException ioobe) { System.out.println("\n Input entered is larger than list size." + "\n Enter an integer between 1 and " + size + " next time.]n"); return true; } System.out.print("Second choice(range's end): "); // second choice to get String entryTwo = jmhUtilities.ReadLine(); // read user input // prevent invalid input of non-numeric type try { choiceTwo = Integer.parseInt(entryTwo); // get first character } catch (NumberFormatException nfe) { System.out.println("\n Invalid input of non-numeric type." + "\n Enter an integer between 1 and " + size + " next time.\n"); return true; } catch (IndexOutOfBoundsException ioobe) { System.out.println("\n Input entered is larger than list size." + "\n Enter an integer between 1 and " + size + " next time.]n"); return true; } // quit the operation if user desires to do so if ( choice < 1 || choiceTwo > size ) { System.out.println("\n Quitting - returning to main menu.\n"); return true; // take the appropriate action as requested } else if ( (choice >= 1 && choice < size) && choiceTwo > 1 ) { // erase professors at choice - 1 location for (int i = choice; i < choiceTwo; i++) { profs.remove(choice); // erase the professor } // notify user of success System.out.println("\n Professors succesfully deleted. 'P' to print.\n"); // error handling } else { System.out.println("\n Invalid input. Please try again." + "\n Next time enter an integer between 1 and " + size + "."); } } return true; }