Menu of Options. Code a Java application that repeatedly displays a list of opti
ID: 3641406 • Letter: M
Question
Menu of Options.
Code a Java application that repeatedly displays a list of options to a user. Depending on which option the user selects, the application must perform a specified task (see below) in response. Once the specified task has completed the menu of options should be redisplayed. One option should be “Exit” which terminates the application.
Each task should be written in its own separate method.
The specified task options are:
a) Display all odd integers between two integers entered by the user. The displayed odd integers should be separated by commas and appear on a single output line. The two numbers entered should be odd and the first number should be less than the second number. Validate each input and reject it if it does not obey the input rules. Repeatedly prompt and get each input until it does obey the input rules.
b) Display the integers in a range (entered by a user) that are exactly divisible by a given integer (also entered by a user). Also display the number of such integers in the entered range. For example: if the entered range is 10 to 100 and the entered divisor is 5 then 19 integers in the range are exactly divisible by 5 being the numbers: 10 15 2 25 … 100. Output the integers as a space separated list on a single line. On the following line output how many integers there are. The entered range should make sense (first less than second) and the entered divisor should be a positive integer. Validate each input and reject it if it does not obey the input rules. Repeatedly prompt and get each input until it does obey the input rules.
c) Display the Collatz sequence (defined below) from a starting number entered by a user. The entered starting number should be a positive integer. Validate the input and reject it if it does not obey the input rule. Repeatedly prompt and get the input until it does obey the input rule.
The Collatz sequence:
Begin the sequence with the entered starting number which becomes the current number. Now build the sequence according to the following rules:
If the current number is the number 1: sequence terminates
If the current number is even: then the next number is the current number divided by 2.
If current number is odd: the next number is (3 * current number + 1)