1st Tsk

 Here is a simple Java program that allows a teacher to enter students' grades and compute their average, highest, and lowest scores using an ArrayList:



import java.util.ArrayList;

import java.util.Scanner;


public class StudentGrades {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        ArrayList<Integer> grades = new ArrayList<>();


        while (true) {

            System.out.print("Enter student grade (or -1 to finish): ");

            int grade = scanner.nextInt();

            if (grade == -1) {

                break;

            }

            grades.add(grade);

        }


        if (grades.isEmpty()) {

            System.out.println("No grades entered.");

        } else {

            int sum = 0;

            int highest = grades.get(0);

            int lowest = grades.get(0);


            for (int grade : grades) {

                sum += grade;

                if (grade > highest) {

                    highest = grade;

                }

                if (grade < lowest) {

                    lowest = grade;

                }

            }


            double average = (double) sum / grades.size();


            System.out.println("Average: " + average);

            System.out.println("Highest: " + highest);

            System.out.println("Lowest: " + lowest);

        }

    }

}



Here's how the program works:


1. It creates an ArrayList to store the student grades.

2. It enters a loop where it continuously asks the teacher to enter student grades.

3. If the teacher enters -1, the loop breaks and the program proceeds to calculate the average, highest, and lowest scores.

4. If no grades were entered, it displays a message indicating so.

5. Otherwise, it calculates the sum of all grades, the highest grade, and the lowest grade.

6. It then calculates the average grade by dividing the sum by the number of grades.

7. Finally, it displays the average, highest, and lowest scores.

Comments

Popular posts from this blog

Rohit Sharma’s Journey to White-Ball Supremacy

THE INDIAN CULTURE QUINTESSENCE