New paste Repaste Download
/******************************************************************************
                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
class Student{
    private int studentId;
    private String studentName;
    private String schoolName;
    private int studentGrade;
    
    int getStudentId(){
        return studentId;
    }
    
    String getStudentName(){
        return studentName;
    }
    
    String getSchoolName(){
        return schoolName;
    }
    
    int getStudentGrade(){
        return studentGrade;
    }
    
    Student(int studentId,String studentName,String schoolName,int studentGrade){
        this.studentId=studentId;
        this.studentName=studentName;
        this.schoolName=schoolName;
        this.studentGrade=studentGrade;
    }
}
class AaryaKaException extends Exception
{
    public AaryaKaException(String message)
    {
        super(message);
    }
}
class GradeCalculator{
    private static ArrayList<Student> StudentList = new ArrayList<>();
    
    ArrayList<Student> getStudentList(){
        return StudentList;
    }
    
    GradeCalculator(ArrayList<Student> StudentList){
        this.StudentList=StudentList;
    }
    
    public static void countPassingStudents(String schoolName){
        int count=0;
        for(Student s : StudentList){
            if(s.getSchoolName().equalsIgnoreCase(schoolName)){
                if(s.getStudentGrade()>=600){
                    count++;
                }
            }
        }
        if(count==0){
            System.out.println("School Name not Present");
        }
        else{
            System.out.println("Passing Students in LPS: "+count);
        }
    }
    
    public static void calculateAverage(String schoolName) throws AaryaKaException{
        double result = 0.0;
        int sum = 0;
        int count = 0;
        for(Student s : StudentList){
            if(s.getSchoolName().equalsIgnoreCase(schoolName)){
                if(s.getStudentGrade()<0){
                    throw new AaryaKaException("Invalid Grades: Grade cannot be negative");
                }
                else{
                    sum+=s.getStudentGrade();
                    count++;
                }  
            }
        }
        if(count==0){
            throw new AaryaKaException("No Student Present");
        }
        else{
            result = (double)sum / count;
            System.out.println("Average grade for "+schoolName+": "+result);
        }
    }
    
    
    
}
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Student> StudentList = new ArrayList<>();
int n = sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++){
    int studentId = sc.nextInt();
    sc.nextLine();
    String studentName = sc.nextLine();
    String schoolName = sc.nextLine();
    int studentGrade = sc.nextInt();
    sc.nextLine();
    StudentList.add(new Student(studentId,studentName,schoolName,studentGrade));
}
String schoolName = sc.nextLine();
GradeCalculator gc = new GradeCalculator(StudentList);
gc.calculateAverage(schoolName);
gc.countPassingStudents(schoolName);
}
}
Filename: None. Size: 3kb. View raw, , hex, or download this file.

This paste expires on 2024-11-19 09:48:20.345176. Pasted through web.