Write a program to read test scores, process scores, and display a final report or save the report into a text file. A report isgenerated for a class of 4 students.A test score is an integer from 0 to 100. There are no extra credits. A letter grade can be assigned as follows:If an average is 90 or greater, the letter grade A is assigned.Otherwise, if an average is 80 or greater, the letter grade B is assigned.Otherwise, if an average is 70 or greater, the letter grade C is assigned.Otherwise, the letter grade F is assigned.
Users can process the scores and display a report like this, save the report into a file, or quit.
Test 1 Test 2 Average Grade
—— —— ——- —–
090 059 074.5 C
082 080 081.0 B039 100 069.5 F089 092 090.5 ASee more information in sample run on next page. I upload a picture of the rest. see the attach. ss the length of array using the instance variable length in arrays class. If an array is full, its length is equal to
ber of elements in the array. Use a for loop as a proper loop.
for (int i = 0; i < testone.length; i++) {
}
stone.length returns the size of array testone.
9
d magic numbers.
puter programming, a magic number is a special constant used for some specific purpose. It is called magic
its value or presence is inexplicable without some additional knowledge. The term magic number also refers to
programming practice of using numbers directly in source code without explanation. In most cases this makes
as harder to read, understand, and maintain, although most guides make an exception for the numbers zero and
r example, a program is more readable if menu items are defined as constants as shown in the right column.
ractice: using "magic numbers”
use the following format.
Good practice: more readable using constants
Use the following format.
final int GRADE REPORT = 1;
final int GRADE REPORT_IN FILE =
final int EXIT = 3;
2;
switch (choice) {
case GRADE REPORT:
h (choice) {
se 1:
//
break;
se 2:
break;
case GRADE REPORT IN FILE:
break;
se 3:
//
break;
break;
case EXIT:
//
break;
}
parallel arrays to store corresponding information of each student at the same index.
t[] testone new int[4];
// Students' test one grades
t[] testTwo new int[4];
// Students' test two grades
uble[] average = new double [4]; // Students' average grades
ar[] grade = new char[4];
// Students' letter grades
Student one
Student two
Student three
Student four
0
1
2
3
ndex value
estone
0
1
3
ndex value
estTwo
0
1
2
3
ndex value
Jerage
O
1
2
3
ndex value
cade
8
to Grade Center!
to generate and display a report.
to generate a report and save it into a file.
to quit.
choice:
When the program runs, this
menu is displayed. Normal
choice 1 or 2 can be selected for
score processing. Abnormal
choice 3 can be selected to quit
the program
ades for testi and test2
1,
ore 1: 90
ore 2: 82
ore 3: 39
core 4: 89
If users choose a normal choice
1. the program prompts for test
one scores, and test two scores. A
sequence of scores of each test is
entered in order.
E 2,
core 1: 59
core 2: 30
core 3: 100
core 4: 9
Test 2
Average
Grade
A report is displayed. Test scores
and average scored are formatted.
Letter grades are assigned.
с
B
059
080
100
092
074.5
081.0
069.5
090.5
ד D
to Grade Center!
to generate and display a report.
to generate a report and save it into a file.
to quit.
choice: -
The same menu is displayed for
more choices till users choose 3
to quit.
rades for testi and test2
t 1,
core 1: 76
core 2: 89
core 3: 40
core 4: 100
In this case, the user chooses to
save the report into a file. After
reading scores, a file name is
scanned. The same report is
created and saved into this file.
Here is the file.
MyReport - Notepad
Edit
Format
View
Help
File
1
t 2,
core 1: 56
core 2: 98
core 3: 99
core 4: 80
he filename: MyReport txt
written into a file: MyReport
Test 1
Test 2 Average Grade
LL
076
089
040
100
056
098
099
080
066.0
093.5
069.5
090.0
A
F
B
to Grade Center!
to generate and display a report.
to generate a report and save it into a file.
to quit.
choice:
Same menu displays, 3 is selected
to quit the program.
7
Decision Structures, loops, files, arrays
Due: see calendar
2 submitted:
n algorithm - a regular text file
va Source code – a Java source file
apporting files if any
ogram to read test scores, process scores, and display a final report or save the report into a text file. A report is
for a class of 4 students.
not required to write a Java class with instance/static members in this project. Write in method main.
Cudy how to write a Java class (chapter 6 and 8) in later lectures.
ce is an integer from 0 to 100. There are no extra credits. A letter grade can be assigned as follows:
average is 90 or greater, the letter grade A is assigned.
wise, if an average is 80 or greater, the letter grade B is assigned.
wise, if an average is 70 or greater, the letter grade C is assigned.
wise, the letter grade F is assigned.
process the scores and display a report like this, save the report into a file, or quit.
1
Test 2
Average
Grade
059
080
100
092
074.5
081.0
069.5
090.5
С
B
F
A
nformation in sample run on next page.
6