Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 61

2 marks

Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)Fill inObjects

Fill in the blanks marked ?1?, ?2? ... so that the code works.

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)
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

Blanks: (t = br.readLine()) != null; st.nextToken(); 2.0; br.close();

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