Project Solution: Determine the Best Performing Section in Final Exams
☰Fullscreen
Table of Content:
Here’s a solution for the project "Determine the Best Performing Section in Final Exams" using Java. This solution will accept student marks, calculate averages for each section, and determine which section performed best.
Solution (Java Code):
import java.util.Scanner; public class BestPerformingSection { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Number of sections and subjects int sections = 3; // A, B, C int subjects = 5; // 5 subjects for each student // Variables to store total marks for each section double[] sectionTotals = new double[sections]; double[] sectionAverages = new double[sections]; int[] studentsPerSection = new int[sections]; // Loop to input the number of students in each section for (int i = 0; i < sections; i++) { String sectionName = (i == 0) ? "A" : (i == 1) ? "B" : "C"; System.out.print("Enter the number of students in Section " + sectionName + ": "); studentsPerSection[i] = scanner.nextInt(); } // Loop through each section to input marks for (int i = 0; i < sections; i++) { String sectionName = (i == 0) ? "A" : (i == 1) ? "B" : "C"; System.out.println("\nEntering marks for Section " + sectionName + ":"); double sectionTotal = 0; // Loop through each student in the section for (int student = 0; student < studentsPerSection[i]; student++) { System.out.println("Enter marks for student " + (student + 1) + ":"); // Loop through each subject for the student for (int subject = 0; subject < subjects; subject++) { System.out.print(" Subject " + (subject + 1) + ": "); double marks = scanner.nextDouble(); sectionTotal += marks; // Add marks to section total } } // Store total marks for the section sectionTotals[i] = sectionTotal; } // Calculate the average score for each section for (int i = 0; i < sections; i++) { sectionAverages[i] = sectionTotals[i] / (studentsPerSection[i] * subjects); } // Compare the averages to find the best performing section String bestSection = "A"; double highestAverage = sectionAverages[0]; if (sectionAverages[1] > highestAverage) { bestSection = "B"; highestAverage = sectionAverages[1]; } if (sectionAverages[2] > highestAverage) { bestSection = "C"; highestAverage = sectionAverages[2]; } // Output the result System.out.println("\n--- Results ---"); System.out.printf("Section A average score: %.2f\n", sectionAverages[0]); System.out.printf("Section B average score: %.2f\n", sectionAverages[1]); System.out.printf("Section C average score: %.2f\n", sectionAverages[2]); System.out.println("The best performing section is: " + bestSection + " with an average score of: " + highestAverage); // Close the scanner scanner.close(); } }
Explanation:
-
Input:
- The program prompts the user to enter the number of students in each section (A, B, and C).
- For each student in a section, the user provides marks for 5 subjects.
-
Total Calculation:
- For each section, the total score is calculated by summing up the marks of all students for all subjects.
-
Average Calculation:
- The program calculates the average score for each section by dividing the total marks by the number of students and subjects in that section.
-
Comparison:
- The averages of the sections (A, B, and C) are compared to determine the section with the highest average score.
-
Output:
- The average score for each section is printed, followed by a statement declaring the section with the highest average score.
Sample Input/Output:
Enter the number of students in Section A: 3 Enter the number of students in Section B: 3 Enter the number of students in Section C: 3 Entering marks for Section A: Enter marks for student 1: Subject 1: 80 Subject 2: 90 Subject 3: 85 Subject 4: 88 Subject 5: 92 Enter marks for student 2: Subject 1: 70 Subject 2: 78 Subject 3: 80 Subject 4: 75 Subject 5: 80 ... ... --- Results --- Section A average score: 81.87 Section B average score: 75.13 Section C average score: 82.20 The best performing section is: C with an average score of: 82.20
What the Students Will Learn:
- Loops: The program demonstrates nested loops for input and processing of data.
- Arrays: Arrays are used to store total marks and averages for each section.
- Conditionals: The comparison logic helps students understand the use of
if-else
statements. - Input/Output Handling: Students learn how to gather input from the user and output formatted results.
- Data Validation: Students can expand this project to handle data validation, such as ensuring marks are within a valid range (0 to 100).
This project not only reinforces basic programming concepts but also teaches students how to structure and process data logically. They can further extend the program by adding features like handling ties, or calculating performance across more subjects.