Given the posted data file called grades.dat that has a list of five students an
ID: 3621698 • Letter: G
Question
Given the posted data file called grades.dat that has a list of five students and their marks on 6 tests, write a program that will:1. Create two arrays. One will be called student and will be an array of five Strings. The second will be a two dimensional array of integer values called mark.
2. Populate the arrays by connecting a scanner object to the file and reading the data into the arrays.
3. Display the arrays with appropriate headings such as:
a. Student Test1 test2 test3 test4 test5 test6
4. Create an array of five double values called studentAverage and populate it with the averages of the grades of the five students.
5. Create an array of double values called testAverages with six elements and populate it with the averages of the marks on the six tests.
6. Display the arrays with the student averages following the student marks and the test averages below the test marks.
7. Display the student’s name and mark for the student with the highest mark on each test.
8. Display the name and average of the student with the highest average on the tests.
Use methods for parts 4, 5, 7 and 8
Explanation / Answer
1) String[] student = new String[5]; //array of strings with length 5 int[][] mark = new int[5][6]; int count = 0; //variable to advance to the new array location of student int countTest=0; 2) BufferedReader bf = new BufferedReader(new FileReader(grades.dat)); Scanner scan = new Scanner(bf); // to read the file elements while(scan.hasNext()){ here you need to read the file line by line depending on the format that was given to you, if you do something like double x = scan.nextDouble() will give you the test score of the double value found in the file... if you do String name = scan.next() will give you the string that's next while it is scanning... it all depends on the format of the elements of your grades.dat file.. use these basic ideas to read the elements and store the names in the student array, would be something like this: student[count++]= (in this case) name; do the same to get the test scores and save them in the mark array.. would be something like this one: mark[row for each student][countTest++]=(in this case)x; }// end of while loop 3)use nested for loops to get the student names and the test scores ..eg String result=""; for(int row=0;rowRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.