7. (6 marks) Write a program togenerate 8 random integers in the range of 10 to 100...
Question:
7. (6 marks)Write a program togenerate 8 random integers in the range of 10 to 100 andask the user if they would like to choose the number ("y" for yes or "n" for no). Add only the numbers chosen to anArrayList, and then display the index, the element value, and a cumulative average (the average of all the numbers printed so far)
REQUIREMENTS
- Your code must useArrayList.
- Your program must use onlyprintf(...) statements toadjust the alignment of your output.
- Your code must usefor-loop.
- The user input is always correct (input verification is not required).
- Your code must work exactly like the following examples (the text in bold indicates the user input).
Example of the program output:
Random number 1 is 72
Would you like to choose this number (y/n): n
Random number 2 is 46
Would you like to choose this number (y/n): y
Random number 3 is 97
Would you like to choose this number (y/n): y
Random number 4 is 81
Would you like to choose this number (y/n): n
Random number 5 is 69
Would you like to choose this number (y/n): n
Random number 6 is 43
Would you like to choose this number (y/n): y
Random number 7 is 77
Would you like to choose this number (y/n): n
Random number 8 is 21
Would you like to choose this number (y/n): y
Index Element Cumulative Average
0 46 46.0
1 97 71.5
2 43 62.0
3 21 51.8