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 to at a time for five scores,and then, write the scores into a file using array list.Sample run: Userentered values are shown in red.Enter score : Enter score : Enter score : Enter score : Enter score : A new file will be created for the report.Enter the new file nameFor 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 selfexplanatory. 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 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 ArrayListint 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 the loop should execute for the next score.
public int size
Returns the number of elements in this list.
To read a userentered 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 userentered 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 eg the next userentered value to the end of the list, the following
method must be used.
public boolean addE 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 userentered file name, pass the file object to the PrintWriter constructor. The file must be stored in the rootJava 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 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 :
Score :
Score :
Score :
Score :
To retrieve the element at index i you must use the get method. public E getint 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
