Going Further Lesson 21 of 21
Java Final Project — Class Record and Grading System
Build a complete console grading system in Java with a Student class, an ArrayList, a menu, input validation, DepEd-style computation, rankings and a saved report.
In this final project, you'll build a class record system like the ones teachers use: add students, enter their component scores, compute quarterly grades with DepEd-style weights, rank the class, and save a report. It combines classes, encapsulation, ArrayList, loops, switch, exceptions and files.
Features
- Add a student with written work, performance task and quarterly exam scores (in percent).
- Compute each quarterly grade: WW 25% + PT 50% + QE 25% (typical for TLE; adjust per subject).
- Show the class list with grades and descriptors.
- Rank students from highest to lowest and show the class average.
- Save a report to
report.txt.
The code
Save it as Main.java. Both classes can be in one file because only Main is public.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
class Student {
private final String name;
private final double ww, pt, qe; // component scores in percent
Student(String name, double ww, double pt, double qe) {
this.name = name;
this.ww = ww;
this.pt = pt;
this.qe = qe;
}
String getName() { return name; }
double getGrade() {
return ww * 0.25 + pt * 0.50 + qe * 0.25;
}
String getDescriptor() {
double g = getGrade();
if (g >= 90) return "Outstanding";
if (g >= 85) return "Very Satisfactory";
if (g >= 80) return "Satisfactory";
if (g >= 75) return "Fairly Satisfactory";
return "Did Not Meet Expectations";
}
@Override
public String toString() {
return String.format("%-18s %6.2f %s", name, getGrade(), getDescriptor());
}
}
public class Main {
static final Scanner sc = new Scanner(System.in);
static final ArrayList<Student> students = new ArrayList<>();
public static void main(String[] args) {
int choice;
do {
System.out.println("\n=== CLASS RECORD ===");
System.out.println("[1] Add student [2] Class list [3] Rankings [4] Save report [0] Exit");
choice = readInt("Choice: ", 0, 4);
switch (choice) {
case 1 -> addStudent();
case 2 -> showList();
case 3 -> showRankings();
case 4 -> saveReport();
case 0 -> System.out.println("Goodbye!");
}
} while (choice != 0);
}
static int readInt(String prompt, int min, int max) {
while (true) {
System.out.print(prompt);
try {
int n = Integer.parseInt(sc.nextLine().trim());
if (n >= min && n <= max) return n;
} catch (NumberFormatException e) {
// fall through to the message below
}
System.out.println("Please enter a number from " + min + " to " + max + ".");
}
}
static void addStudent() {
System.out.print("Name: ");
String name = sc.nextLine().trim();
if (name.isEmpty()) {
System.out.println("Name can't be empty.");
return;
}
int ww = readInt("Written work (%): ", 0, 100);
int pt = readInt("Performance task (%): ", 0, 100);
int qe = readInt("Quarterly exam (%): ", 0, 100);
Student s = new Student(name, ww, pt, qe);
students.add(s);
System.out.printf("Added %s with grade %.2f%n", name, s.getGrade());
}
static void showList() {
if (students.isEmpty()) {
System.out.println("No students yet.");
return;
}
for (Student s : students) System.out.println(s);
}
static void showRankings() {
if (students.isEmpty()) {
System.out.println("No students yet.");
return;
}
List<Student> ranked = new ArrayList<>(students);
ranked.sort(Comparator.comparingDouble(Student::getGrade).reversed());
double sum = 0;
int rank = 1;
for (Student s : ranked) {
System.out.println(rank++ + ". " + s);
sum += s.getGrade();
}
System.out.printf("Class average: %.2f%n", sum / ranked.size());
}
static void saveReport() {
List<String> lines = new ArrayList<>();
lines.add("CLASS RECORD REPORT");
for (Student s : students) lines.add(s.toString());
try {
Files.write(Path.of("report.txt"), lines);
System.out.println("Saved to report.txt");
} catch (IOException e) {
System.out.println("Could not save: " + e.getMessage());
}
}
}
Sample run
Output
=== CLASS RECORD === [1] Add student [2] Class list [3] Rankings [4] Save report [0] Exit Choice: 1 Name: Maria Clara Written work (%): 92 Performance task (%): 95 Quarterly exam (%): 88 Added Maria Clara with grade 92.50 === CLASS RECORD === [1] Add student [2] Class list [3] Rankings [4] Save report [0] Exit Choice: 1 Name: Jose Rizal Written work (%): 85 Performance task (%): 80 Quarterly exam (%): 90 Added Jose Rizal with grade 83.75 === CLASS RECORD === [1] Add student [2] Class list [3] Rankings [4] Save report [0] Exit Choice: 3 1. Maria Clara 92.50 Outstanding 2. Jose Rizal 83.75 Satisfactory Class average: 88.13
What each part teaches
| Part | Concepts |
|---|---|
Student class | Encapsulation, constructor, methods, toString |
students list | ArrayList of objects, static fields |
| Menu | do-while + arrow switch |
readInt | Input validation with try-catch and loops |
showRankings | Copying and sorting with a Comparator |
saveReport | Writing a file and handling IOException |
Challenges
- Add an option to delete a student by name.
- Use DepEd's transmutation table to convert initial grades to transmuted grades.
- Load students from
report.txt(or a CSV file) when the program starts. - Track four quarters per student and compute the final grade.
- Build a graphical version with Java Swing or JavaFX (NetBeans has a drag-and-drop designer).
What's next?
Congratulations on completing the Java course! 🎉 You can now:
- Learn SQL and connect Java to a database with JDBC.
- Try Android development with Android Studio.
- Compare with C#, which is very similar to Java, or C++.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04