private static int readMenuChoice(BufferedReader reader, int max) {
        int result = 0;
        while (true) {
            String choice = null;
            try {
                choice = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                result = Integer.parseInt(choice);
            } catch (NumberFormatException ignored) {
            }

            if (result >= 1 && result <= max) {
                break;
            }
            System.out.println ("Please enter a number corresponding to one of the items in the menu:");
        }
        return result;
    }