Thuta Learning
AdvancedProgrammingbeginner

Mini Project

Relax. We'll talk through this in plain words — no textbook voice.

In this mini project, we'll build a Simple Student Grade Manager. We'll store student names in an ArrayList, store marks in a HashMap, calculate each student's result with a loop, and split out the grade logic into its own method. This small project packs Java basics, collections, methods, and control flow all into one practice session.

java
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
  static String getGrade(int mark) {
    if (mark >= 80) {
      return "A";
    } else if (mark >= 60) {
      return "B";
    } else if (mark >= 40) {
      return "C";
    } else {
      return "Fail";
    }
  }

  public static void main(String[] args) {
    ArrayList<String> students = new ArrayList<String>();
    students.add("Aung");
    students.add("Mya");
    students.add("Htet");

    HashMap<String, Integer> marks = new HashMap<String, Integer>();
    marks.put("Aung", 85);
    marks.put("Mya", 67);
    marks.put("Htet", 38);

    for (String student : students) {
      int mark = marks.get(student);
      String grade = getGrade(mark);
      System.out.println(student + " - Mark: " + mark + ", Grade: " + grade);
    }
  }
}

getGrade() method returns a grade based on the mark. students ArrayList stores the student names. The marks HashMap uses the student name as the key and stores the mark as the value. An enhanced for loop reads through each student and prints out their mark and grade.

You should see
Aung - Mark: 85, Grade: A Mya - Mark: 67, Grade: B Htet - Mark: 38, Grade: Fail

Real-World Use

You can level up this project later by adding user input, calculating average marks, finding the highest score, saving to a file, or adding a GUI.

What's Next

Once you finish this mini project, try combining Java OOP with Collections and splitting it into Student, Course, and GradeService classes.

Easy traps

  • Calling marks.get(student) when that student's name isn't in the HashMap can return null. In a real app, you should check whether the key exists first with containsKey().
Mini Project | Thuta Learning