public static String selectOne ( final String title , final String [ ] optionNames , final String [ ] optionValues , final int defaultOption ) { if ( optionNames . length != optionValues . length ) { throw new IllegalArgumentException ( "option names and values must have same length" ) ; } ConsoleMenu . println ( "Please chose " + title + DEFAULT_TITLE + defaultOption + ")" ) ; for ( int i = 0 ; i < optionNames . length ; i ++ ) { ConsoleMenu . println ( i + 1 + ") " + optionNames [ i ] ) ; } int choice ; do { choice = ConsoleMenu . getInt ( "Your Choice 1-" + optionNames . length + ": " , defaultOption ) ; } while ( choice <= 0 || choice > optionNames . length ) ; return optionValues [ choice - 1 ] ; }
Generates a menu with a list of options and return the value selected .