Introduction
Every college publishes result sheets, and most of them are still built in spreadsheets by hand. This program does it from plain text: it validates each line, applies a per-subject pass mark, assigns grades, ranks the class with shared ranks for ties, and summarises how the class performed.
Problem statement
Objectives
- Model a student as a record with behaviour (total, percentage, grade)
- Validate input line by line with exceptions
- Sort with a Comparator chain and compute competition ranks
- Use streams to compute statistics
Features
- Any number of subjects, named on the first line
- Validation with clear rejection messages
- Shared ranks for equal totals (1, 2, 2, 4)
- Grades O, A+, A, B, C, D and F; per-subject pass mark
- Pass rate, class average and subject toppers including ties
Concepts demonstrated
- Records
- Input validation
- Comparator.comparingInt / thenComparingInt
- Streams (filter, mapToDouble, max)
- Formatted output
System architecture
Student is a record holding the roll number, name and an int array of marks; it computes its own total, percentage, pass status and grade. main reads the subject line, then parses each student line inside a try block: NumberFormatException and IllegalArgumentException (for range and duplicate errors) are caught and reported with the line number. After reading, the list is sorted by total descending then roll ascending, and printed with ranks that only change when the total changes. Statistics and toppers use streams over the list.
Folder structure
Complete source code
src/Main.java
What each file does
- src/Main.java
- The
Studentrecord with its grading rules, the validating reader, the ranked report and the statistics.
How to run it
Compile
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
Maths Physics Java 101 Asha 92 88 95 102 Ravi 67 30 80 103 Meera 85 91 78 104 John 45 58 62 105 Priya 85 91 78 106 Karan 101 70 60 107 Sam 72 seventy 70 101 Duplicate 50 50 50 108 Omar 55 61
Testing
- Compile and run with
tests/sample-input.txtand compare withtests/expected-output.txt. - Four lines are rejected: a mark of 101, the word 'seventy', a duplicate roll number and a line with only two marks.
- Meera and Priya have equal totals, so both are ranked 2 and the next student is ranked 4.
- Ravi scores 30 in Physics, so he fails even though his percentage is 59%.
Common errors
InputMismatchException or NumberFormatException crashes the program
Read whole lines and parse them inside try/catch, as the program does, instead of calling nextInt directly.
Percentages print as 91.0 instead of 91.67
Divide using doubles: total() * 100.0 / (marks.length * 100).
Possible improvements
- Read subject-wise maximum marks instead of assuming 100
- Export the result sheet as CSV
- Add a grace-marks rule for students who miss a pass by 1–2 marks
Additional challenges
- 1Print each student's best and worst subject.
- 2Compute the median and standard deviation of percentages.
- 3Draw a text histogram of grades.
Built and tested it yourself? Mark it to update your dashboard.