Question: java write a program that prompts users to enter a score ( 0 to 1 0 0 ) at a time for five scores,and then,

java write a program that prompts users to enter a score(0 to 100) at a time for five scores,and then, write the scores into a file using array list.Sample run: User-entered values are shown in red.Enter score 1: 90Enter score 2: 82Enter score 3: 39Enter score 4: 89Enter score 5: 99A new file will be created for the report.Enter the new file name(For example, MyReport.txt.):YourReport.txtReport written into a file: YourReport.txt
First, at the beginning of main, declare variables for the inputs, the outputs, and important values of the process. Variable names should be descriptive and self-explanatory. No comments should be needed for variables.You must replace the score arrays with array lists. Integer class is the wrapper class for int.
Array lists can store objects only. When storing integers, we store them as Integer objects. For example, the following shows how to create an array list with an initial capacity of 10 tostore Integer objects.
ArrayList scores = new ArrayList();
You may use one of the following constructors.
public ArrayList()
Constructs an empty list with an initial capacity of ten.
public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity. You must write one prompt statement in a for loop that executes five times. When
executed, the loop prompts user to enter the next score and add it into the end of the array
list. The prompt should end with a serial number .
A new file will be created for the report.
Enter the new file name (For example, MyReport.txt.):
YourReport.txt
Report written into a file: YourReport.txt. The following method checks the size of an array list. The size may be less than or equal to
the capacity of the list. The for loop should be controlled by the size of the array list. If the size of the array list hasnt reach 5, the loop should execute for the next score.
public int size()
Returns the number of elements in this list.
To read a user-entered value, you will need to create a Scanner object using new operator
and a Scanner constructor and save it into a Scanner variable - an object reference.
To read a user-entered value such as an int, use the Scanner object reference to invoke the
following instance method in Scanner class. The
public int nextInt()
Scans the next token of the input as an int.
To add an element (e.g., the next user-entered value) to the end of the list, the following
method must be used.
public boolean add(E e)
Appends the specified element to the end of this list.
In addition to the five scores, the new file name is entered as well.
You must create a File object using the user-entered file name, pass the file object to the PrintWriter constructor. The file must be stored in the root/Java project folder, the default folder. Use the PrintWriter object reference to call println method to write the scores stored
int the array to the output file.
You can only use println once in a for loop that executes five times. You must use the size
method (instead of 5) to determine when to terminate the for loop. When executed, the
loop combines Score # with the score in the array in the required format, and then, writes
the combined value into the output file.
Score 1: 90
Score 2: 82
Score 3: 39
Score 4: 89
Score 5: 99
To retrieve the element at index i, you must use the get method. public E get(int index)
Returns the element at the specified position in this list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!