Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in java write a program that prompts users to enter a score ( 0 to 1 0 0 ) at a time for five scores,
in 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.
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.txt
Report written into a file: YourReport.txt
The following shows how the scores are stored in the output file: YourReport.txt
You must use the required Java classes and loop statements specified in the following instructions.
Start your eclipse, go to the same workspace as your lab
Create a new Java Project using FileNewJava Project in the menu bar. Enter a project name. If
package explorer is invisible, show it using WindowShow ViewPackage Explorer.
Add a package to folder src Right click src choose NewPackage in the menu bar. Enter a package
name.
You must use an int to store the scores.
Next, translate the input module of your algorithm. This is a block for which comments are
needed. You may turn the sentences in the input module of your algorithm into comments
here. If needed, break this block into subblocks and add more comments. Write Java
statements according to the comments.
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 store it into the next location of
the score array. The prompt should end with a serial number
Enter score :
Enter score :
Enter score :
Enter score :
Enter score :
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
You must have the required prompt for the input. You must use length instead of the
instance variable of arrays, to determine the terminating index in the for loop.
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.
public int nextInt
Scans the next token of the input as an int.
In addition to the five scores, the new file name is entered as well.
Next, translate the process module of your algorithm. This is a block for which comments
are needed. You may turn the sentences in the process module of your algorithm into
comments here. If needed, break this block into subblocks and add more comments. Write
Java statements according to the comments.
For this lab, there is not much process since the inputs are written to an output file.
Lastly, translate the output module of your algorithm. This is a block for which comments
are needed. You may turn the sentences in the output module of your algorithm into
comments here. If needed, break this block into subblocks and add more comments. Write
Java statements according to the comments. The outputs must be displayed in a format
shown in the sample runs.
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. 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started