Question: DESCRIPTION Write a Java program that will compute and display the final grades for a list of students. A student's final grade is determined from
DESCRIPTION
Write a Java program that will compute and display the final grades for a list of students. A student's final grade is determined from the scores obtained in the class tests. Each student in the class may be given a different number of tests as determined by the instructor. The final grade is determined by the average of the scores in all the tests given. In this assignment, you will input from a file called in.txt and output to a file called out.txt.
This exercise will provide for assigning a CR or NCR (Credit or No Credit) grade.
For each student, the program will input student id, name, the number of tests given and scores in each of the tests.
Additionally, it will input the grade type: Letter or Credit. The grade type of Letter will indicate that student will receive a grade of A, B, C, D, or F. The grade type of Credit will indicate that the student will receive a grade of CR or NCR.
The scores in each of the tests will vary from 0 to 100. Each test will carry the same weight. The final grade will be computed by taking the average of the scores in all the tests given (i.e. by adding the scores in all the tests and dividing it with the number of tests given). The final grade will be assigned depending upon the percentage of total points in the tests given as follows:
A 90 to 100%
B 80 to 89%
C 70 to 79%
D 60 to 69%
F 0 to 59%
Additionally, for a grade type of Credit, the grade will be determined as follows:
If the student qualifies for a C or better grade, the student will be assigned a CR (Credit) grade. Otherwise, the student will be assigned an NCR (No Credit) grade.
Creating File IO Objects
For doing this assignment, you will create a BufferedReader object to input data from the text file line at a time. Also, you will create a PrintWriter object to write data to the file a String at a time.
Getting Student Count
It is suggested that you put student count as the first line of data in the input file. Different methods of determining the total number of students are described below.
Prompt the User for the Count
Prompt the user for entering the total number of students in the file using JOptionPane.showInputDialog.
Put the Count in the File
Put the total number of students as the first line of data in the input file. Input this value from the file and create a StudentExtarray of that size. Then input and process student data from the file.
Read File Twice
Create a file io object encapsulating the input file. Input data from the file line by line using the file io object. Keep a count of the number of lines read. Issue a close on the file io object. Create an array of StudentExt references of size above. Create a file io object encapsulating the input file a second time. Input data from the file line at a time. Each line will contain one student data. For each line read, create a StudentExt object and save its reference in the array created above. After all data is read and StudentExt objects are created, issue a close on the file io object. This will result in closing the file.
TESTING:
Input
The in.txt file should contain the following:
1, John Adam, 3, 93, 91, 100, Letter
2, Raymond Woo, 3, 65, 68, 63, Letter
3, Rick Smith, 3, 50, 58, 53, Letter
4, Ray Bartlett, 3, 62, 64, 69, Letter
5, Mary Russell, 3, 93, 90, 98, Letter
6, Andy Wong, 3, 89,88,84, Letter
7, Jay Russell, 3, 71,73,78, Letter
8, Jimmie Wong, 3, 70,77,72, Letter
9, Jackie Chan, 3, 85,89,84, Letter
10, Susan Wu, 3, 80,88,84, Letter
11, Bruce Lee, 4, 74, 79, 72, 75, Credit
12, Chuck Norris, 5, 63, 64, 62, 60, 68, Credit
13, Jet Li, 3, 85, 83, 89, Credit
14, Jessica Lauser, 3, 82, 84, 87, Letter
15, Mahnoosh Nik-Ahd, 2, 98, 99, Letter
In the above data, for the first entry, id is 1, name is John Adam, test scores are 93, 91, 100 and grade type is letter grade.
Output
After running the program, out.txt file should contain the following:
1 John Adam (A)
5 Mary Russell (A)
15 Mahnoosh Nik-Ahd (A)
6 Andy Wong (B)
9 Jackie Chan (B)
10 Susan Wu (B)
14 Jessica Lauser (B)
7 Jay Russell (C)
8 Jimmie Wong (C)
2 Raymond Woo (D)
4 Ray Bartlett (D)
3 Rick Smith (F)
11 Bruce Lee (CR)
13 Jet Li (CR)
12 Chuck Norris (NCR)
Please show me the source code and the contents of in.txt and out.txt file, thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
