PRASHNIKAप्रश्निका
‹ Back to the paper

A class teacher has kept the records of the marks obtained in Physics and Computer Science of 3…

Computer Science20252 marksShort answer
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)
Student NamePhysicsComputer Science
Anurag9095
Brijesh9595
Toshali97100
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.
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 StuFile

Answer

Answer

AI
?1? (t = br.readLine()) != null ?2? st.nextToken() ?3? 2.0 ?4? fr.close();
Objects

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 61.