0Pricing
Java Academy · Aula

Mini-projeto 2D: boletim de notas

Mini-projeto: crie um pequeno boletim usando uma matriz 2D de inteiros. Imprima tabelas alinhadas, calcule as médias por aluno e por atividade, encontre os melhores desempenhos, aplique um ajuste às notas e gere um relatório-resumo.

Mini-projeto 2D: boletim de notas é uma aula grátis de Java Academy no CoddyKit. Esta é a aula 4 de 6. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Java Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Java Academy inclui 6 aulas no total.

Visão geral do projeto

Objetivo do projeto: representar um livro de notas como uma matriz bidimensional de int, em que cada linha corresponde a um estudante e cada coluna corresponde a uma tarefa, um questionário ou uma prova. Você imprimirá uma tabela alinhada, calculará médias por estudante e por atividade, encontrará o melhor estudante e a melhor atividade, ajustará as notas e gerará um relatório resumido.

Siga as etapas e execute cada exemplo de código na ordem. Nenhuma entrada é necessária.

Criar e imprimir

Etapa 1: crie uma pequena matriz de notas e imprima-a com colunas alinhadas. Usamos um auxiliar para calcular as larguras das colunas e um impressor que preenche cada valor.

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);
				  }
				}
				

Médias por linha e coluna

Etapa 2: calcule as médias por estudante (linha) e por atividade (coluna). As médias das colunas devem verificar o comprimento de cada linha para funcionar com vetores irregulares.

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));
					}
				  }
				}
				

Melhor estudante e atividade

Etapa 3: encontre o melhor estudante (maior média da linha) e a melhor atividade (maior média da coluna).

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) + ")");
				  }
				}
				

Ajustar notas

Etapa 4: aplique um ajuste fixo (por exemplo, +5 pontos por nota, limitado a 100) e imprima as matrizes antes e depois.

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);
				  }
				}
				

Relatório resumido

Etapa 5: gere um relatório simples: médias por estudante e média geral da turma. (Você poderia estender isso para notas em letras mais tarde.)

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)));
				  }
				}
				

Verificação da média do estudante

Verificação rápida: qual fórmula calcula a média do estudante r?

Recapitulação e próximo passo

Recapitulação: Você modelou um diário de notas com uma matriz 2D, imprimiu tabelas alinhadas, calculou médias por linha e coluna, encontrou os melhores desempenhos, ajustou as notas e produziu um relatório resumido. A seguir: reúna esses utilitários em uma classe auxiliar reutilizável.

Perguntas Frequentes

A aula “Mini-projeto 2D: boletim de notas” é grátis?

Sim — o texto completo de “Mini-projeto 2D: boletim de notas” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Java Academy, atualize para CoddyKit PRO. O curso de Java Academy inclui 6 aulas no total.

O que vou aprender em “Mini-projeto 2D: boletim de notas”?

Mini-projeto: crie um pequeno boletim usando uma matriz 2D de inteiros. Imprima tabelas alinhadas, calcule as médias por aluno e por atividade, encontre os melhores desempenhos, aplique um ajuste às… Você pratica Java Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Java Academy?

Nenhuma experiência prévia é necessária. Java Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 6.

Quanto tempo leva a aula “Mini-projeto 2D: boletim de notas”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Java Academy?

Sim. Cada aula de Java Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Noções básicas de matrizes 2D e iteração aninhada
  2. Matrizes irregulares e formatação de tabelas
  3. Máximos por linha/coluna, transposição e formatação
  4. Mini-projeto 2D: boletim de notas
  5. Utilitários 2D como classe auxiliar (refatoração)
  6. Limpeza e validação de dados 2D
← Voltar para Java Academy