0Pricing
Java Academy · Lesson

2D Mini-Project: Gradebook

Mini-project: build a small gradebook using a 2D int matrix. Print aligned tables, compute per-student and per-assignment averages, find best performers, curve scores, and output a summary report.

2D Mini-Project: Gradebook is a free Java Academy lesson on CoddyKit — lesson 4 of 6. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 6 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Project Overview

Project goal: Represent a gradebook as a 2D int matrix where each row is a student and each column is a homework/quiz/exam. You will print an aligned table, compute per-student and per-assignment averages, find the top student/assignment, curve scores, and generate a summary report.

Follow the scenes and run each code sample in order. No input is required.

Build & Print

Step 1: Create a small gradebook matrix and print it with aligned columns. We use a helper to compute column widths and a printer that pads each value.

public class Main {
				  // Join helper for one-dimensional arrays (space-separated)
				  static String join(int[] a) {
					String s = "";
					for (int i = 0; i < a.length; i = i + 1) {
					  s = s + a[i] + (i + 1 < a.length ? " " : "");
					}
					return s;
				  }

				  // Compute column widths for aligned printing (jagged-aware)
				  static int[] widths(int[][] m) {
					int maxCols = 0;
					for (int r = 0; r < m.length; r = r + 1) {
					  if (m[r].length > maxCols) maxCols = m[r].length;
					}
					int[] w = new int[maxCols];
					for (int r = 0; r < m.length; r = r + 1) {
					  for (int c = 0; c < m[r].length; c = c + 1) {
						int len = Integer.toString(m[r][c]).length();
						if (len > w[c]) w[c] = len;
					  }
					}
					for (int c = 0; c < w.length; c = c + 1) if (w[c] < 1) w[c] = 1;
					return w;
				  }

				  // Print matrix with aligned columns
				  static void printAligned(int[][] m) {
					int[] w = widths(m);
					for (int r = 0; r < m.length; r = r + 1) {
					  String line = "";
					  for (int c = 0; c < m[r].length; c = c + 1) {
						String s = Integer.toString(m[r][c]);
						while (s.length() < w[c]) s = " " + s;
						line = line + s + (c + 1 < m[r].length ? " " : "");
					  }
					  System.out.println(line);
					}
				  }

				  public static void main(String[] args) {
					// Create a 4x5 gradebook (4 students, 5 assignments)
					int[][] g = {
					  {78, 85, 90, 88, 92},
					  {95, 91, 89, 93, 87},
					  {60, 72, 70, 68, 75},
					  {88, 84, 79, 85, 90}
					};

					System.out.println("Gradebook (rows: students, cols: assignments):");
					printAligned(g);
				  }
				}
				

Row/Col Averages

Step 2: Compute per-student (row) and per-assignment (column) averages. Column averages must guard each row's length to be jagged-safe.

public class Main {
				  // Average of one row (student r)
				  static double rowAverage(int[][] g, int r) {
					int sum = 0;
					for (int c = 0; c < g[r].length; c = c + 1) sum = sum + g[r][c];
					return (double) sum / g[r].length;
				  }

				  // Average of one column (assignment c)
				  static double colAverage(int[][] g, int c) {
					int sum = 0;
					int count = 0;
					for (int r = 0; r < g.length; r = r + 1) {
					  if (c < g[r].length) { sum = sum + g[r][c]; count = count + 1; }
					}
					return (double) sum / count;
				  }

				  public static void main(String[] args) {
					int[][] g = {
					  {78, 85, 90, 88, 92},
					  {95, 91, 89, 93, 87},
					  {60, 72, 70, 68, 75},
					  {88, 84, 79, 85, 90}
					};

					// Compute per-student averages
					for (int r = 0; r < g.length; r = r + 1) {
					  double avg = rowAverage(g, r);
					  System.out.println("student " + r + " avg = " + String.format("%.2f", avg));
					}

					// Compute per-assignment averages
					int assignments = g[0].length;
					for (int c = 0; c < assignments; c = c + 1) {
					  double avg = colAverage(g, c);
					  System.out.println("assignment " + c + " avg = " + String.format("%.2f", avg));
					}
				  }
				}
				

Best Student/Assignment

Step 3: Find the top student (highest row average) and the top assignment (highest column average).

public class Main {
				  static double rowAverage(int[][] g, int r) {
					int sum = 0;
					for (int c = 0; c < g[r].length; c = c + 1) sum = sum + g[r][c];
					return (double) sum / g[r].length;
				  }

				  static double colAverage(int[][] g, int c) {
					int sum = 0;
					int count = 0;
					for (int r = 0; r < g.length; r = r + 1) { if (c < g[r].length) { sum = sum + g[r][c]; count = count + 1; } }
					return (double) sum / count;
				  }

				  public static void main(String[] args) {
					int[][] g = {
					  {78, 85, 90, 88, 92},
					  {95, 91, 89, 93, 87},
					  {60, 72, 70, 68, 75},
					  {88, 84, 79, 85, 90}
					};

					// Find top student by average
					int bestStudent = -1;
					double bestAvg = -1.0;
					for (int r = 0; r < g.length; r = r + 1) {
					  double avg = rowAverage(g, r);
					  if (avg > bestAvg) { bestAvg = avg; bestStudent = r; }
					}

					// Find top assignment by average
					int assignments = g[0].length;
					int bestAssign = -1;
					double bestCol = -1.0;
					for (int c = 0; c < assignments; c = c + 1) {
					  double avg = colAverage(g, c);
					  if (avg > bestCol) { bestCol = avg; bestAssign = c; }
					}

					System.out.println("top student = " + bestStudent + " (avg=" + String.format("%.2f", bestAvg) + ")");
					System.out.println("top assignment = " + bestAssign + " (avg=" + String.format("%.2f", bestCol) + ")");
				  }
				}
				

Curve Scores

Step 4: Apply a flat curve (e.g., +5 points per score, capped at 100) and print the before/after matrices.

public class Main {
				  // Add a flat curve of k points (capped at 100)
				  static void curve(int[][] g, int k) {
					for (int r = 0; r < g.length; r = r + 1) {
					  for (int c = 0; c < g[r].length; c = c + 1) {
						int v = g[r][c] + k;
						if (v > 100) v = 100;
						g[r][c] = v;
					  }
					}
				  }

				  static void print(int[][] g) {
					for (int r = 0; r < g.length; r = r + 1) {
					  for (int c = 0; c < g[r].length; c = c + 1) {
						System.out.print(g[r][c] + (c + 1 < g[r].length ? " " : ""));
					  }
					  System.out.println();
					}
				  }

				  public static void main(String[] args) {
					int[][] g = {
					  {78, 85, 90, 88, 92},
					  {95, 91, 89, 93, 87},
					  {60, 72, 70, 68, 75},
					  {88, 84, 79, 85, 90}
					};

					System.out.println("before curve:");
					print(g);
					curve(g, 5); // +5 points each
					System.out.println("after curve (+5, capped at 100):");
					print(g);
				  }
				}
				

Summary Report

Step 5: Generate a simple report: per-student averages and overall class average. (You could extend this to letter grades later.)

public class Main {
				  static double rowAverage(int[][] g, int r) {
					int sum = 0;
					for (int c = 0; c < g[r].length; c = c + 1) sum = sum + g[r][c];
					return (double) sum / g[r].length;
				  }

				  static double overallAverage(int[][] g) {
					int sum = 0;
					int count = 0;
					for (int r = 0; r < g.length; r = r + 1) {
					  for (int c = 0; c < g[r].length; c = c + 1) { sum = sum + g[r][c]; count = count + 1; }
					}
					return (double) sum / count;
				  }

				  public static void main(String[] args) {
					int[][] g = {
					  {83, 90, 95, 93, 97},  // assume already curved values
					  {100, 96, 94, 98, 92},
					  {65, 77, 75, 73, 80},
					  {93, 89, 84, 90, 95}
					};

					// Print each student average
					for (int r = 0; r < g.length; r = r + 1) {
					  double avg = rowAverage(g, r);
					  System.out.println("student " + r + " avg = " + String.format("%.2f", avg));
					}

					// Print overall average
					System.out.println("overall avg = " + String.format("%.2f", overallAverage(g)));
				  }
				}
				

Student Avg Check

Quick check: Which formula computes the average of student r?

Recap & Next

Recap: You modeled a gradebook with a 2D array, printed aligned tables, computed row/column averages, found top performers, curved scores, and produced a summary report. Next: wrap these utilities into a reusable helper class.

Frequently asked questions

Is the “2D Mini-Project: Gradebook” lesson free?

Yes — the full text of “2D Mini-Project: Gradebook” is free to read here on the web, and the Java Academy course includes 6 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “2D Mini-Project: Gradebook”?

Mini-project: build a small gradebook using a 2D int matrix. Print aligned tables, compute per-student and per-assignment averages, find best performers, curve scores, and output a summary report. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 6, so you can start here or from the beginning and move at your own pace.

How long does the “2D Mini-Project: Gradebook” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. 2D Array Basics & Nested Iteration
  2. Jagged Arrays & Table Formatting
  3. Row/Column Maxima, Transpose & Formatting
  4. 2D Mini-Project: Gradebook
  5. 2D Utilities as a Helper Class (Refactor)
  6. 2D Data Cleaning & Validation
← Back to Java Academy