‹ Back to the paper
A class teacher has kept the records of the marks obtained in Physics and Computer Science of 3…
A class teacher has kept the records of the marks obtained in Physics and Computer Science of 3 students along with the students’ name. Write a java program to display the name of those students, whose average marks are highest.
File name is Student.txt (Assume that following data is written in file)
Now, there are four places in the code marked as ?1?, ?2?, ?3? and ?4? and they must be replaced by the statements so that the program runs correctly.
| Student Name | Physics | Computer Science |
|---|---|---|
| Anurag | 90 | 95 |
| Brijesh | 95 | 95 |
| Toshali | 97 | 100 |
import java.util.*;
import java.io.*;
class StuFile
{
public static void calculate() throws IOException
{
FileReader fr = new FileReader("Student.txt");
BufferedReader br = new BufferedReader(fr);
String t, name, name1;
int ph, co;
double avg;
double max = 0;
while(?1?)
{
StringTokenizer st = new StringTokenizer(t);
name = ?2?; // Student name
ph = Integer.parseInt(st.nextToken()); // Physics marks
co = Integer.parseInt(st.nextToken()); // Computer Science marks
avg = (ph + co) / ?3?;
System.out.println(name + "- " + ph + ", " + co + ", " + avg);
if (max < avg)
{
max = avg;
name1 = name;
} // end of if
} // end of outer while
System.out.println("Name of students with highest average =" + name1);
?4?
} // end of calculate method
} // end of class StuFileAnswer
Answer
AI?1? (t = br.readLine()) != null
?2? st.nextToken()
?3? 2.0
?4? fr.close();
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 61.