From 993aad4128cf3a918b1c4229357bd89c5a8bce29 Mon Sep 17 00:00:00 2001 From: Miuroro Date: Thu, 7 May 2026 20:56:50 +0200 Subject: [PATCH 1/4] added student logic in Student.java --- task-1/com.hyfacademy/model/Student.java | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java index e69de29..ec1ca7d 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -0,0 +1,50 @@ +package com.hyfacademy.model; + +import com.hyfacademy.util.GradeUtils; + +public class Student { + private String name; + private String studentId; + private int[] grades; + private static int totalStudents = 0; + + public Student(String name, String studentId) { + this.name = name; + this.studentId = studentId; + this.grades = new int[5]; + totalStudents++; + } + +// Getters + public String getName() { + return name; + } + public String getStudentId() { + return studentId; + } + public int[] getGrades() { + return grades; + } + public static int getTotalStudents() { + return totalStudents; + } + +// Setter + public void setGrade(int moduleIndex, int grade) { + if (moduleIndex < 0 || moduleIndex > 4) { + System.out.println("Error: moduleIndex must be between 0 and 4."); + return; + } + if (grade < 0 || grade > 100) { + System.out.println("Error: grade must be between 0 and 100."); + return; + } + grades[moduleIndex] = grade; + } + +// %s for strings and %.2f for decimal numbers with 2 decimal numbers with 2 digits after the point, like 72.40 + public String toString() { + double average = GradeUtils.calculateAverage(grades); + return String.format("[%s] %s — Avg: %.2f — %s", studentId, name, average, GradeUtils.isPassing(average) ? "PASS" : "FAIL"); + } +} From 093c23c05f1f10eda5f0f3c945247cd1008a454b Mon Sep 17 00:00:00 2001 From: Miuroro Date: Thu, 7 May 2026 21:00:08 +0200 Subject: [PATCH 2/4] added grade calculations and formatting logic in GradeUtils.java --- task-1/com.hyfacademy/util/GradeUtils.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/task-1/com.hyfacademy/util/GradeUtils.java b/task-1/com.hyfacademy/util/GradeUtils.java index e69de29..cacbb69 100644 --- a/task-1/com.hyfacademy/util/GradeUtils.java +++ b/task-1/com.hyfacademy/util/GradeUtils.java @@ -0,0 +1,57 @@ +package com.hyfacademy.util; + +public final class GradeUtils { + public static final int MODULE_PASS_MARK = 55; + public static final double TRACK_PASS_AVERAGE = 60.0; + public static final int MODULE_COUNT = 5; + public static final String[] MODULE_NAMES = { + "Java Basics", + "Control Flow", + "OOP Fundamentals", + "Arrays & Collections", + "Input & Output" + }; + + private GradeUtils() { + } + + public static double calculateAverage(int[] grades) { + if (grades == null || grades.length == 0) { + return 0.0; + } + int total = 0; + for (int grade : grades) { + total += grade; + } + return (double) total / grades.length; + } + + public static boolean isPassing(double average) { + return average >= TRACK_PASS_AVERAGE; + } + + public static boolean isModulePassing(int grade) { + return grade >= MODULE_PASS_MARK; + } + + public static String getLetterGrade(double average) { + if (average >= 90.0) { + return "A"; + } + if (average >= 80.0) { + return "B"; + } + if (average >= 70.0) { + return "C"; + } + if (average >= 60.0) { + return "D"; + } + return "F"; + } + +// %3d to print integer with 3 characters width, right-aligned + public static String formatGrade(int grade) { + return String.format("%3d", grade); + } +} From 7d3a40d540b6aa6d0442fb4d0ea58eb51ae09ec1 Mon Sep 17 00:00:00 2001 From: Miuroro Date: Thu, 7 May 2026 21:04:23 +0200 Subject: [PATCH 3/4] added The service layer of students list and application logic in GradeService.java --- .../com.hyfacademy/service/GradeService.java | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/task-1/com.hyfacademy/service/GradeService.java b/task-1/com.hyfacademy/service/GradeService.java index e69de29..ce8d5f2 100644 --- a/task-1/com.hyfacademy/service/GradeService.java +++ b/task-1/com.hyfacademy/service/GradeService.java @@ -0,0 +1,164 @@ +package com.hyfacademy.service; + +import com.hyfacademy.model.Student; +import com.hyfacademy.util.GradeUtils; + +import java.util.Scanner; + +public class GradeService { + private static final int MAX_STUDENTS = 20; + + private final Student[] students; + private int studentCount; + private final Scanner scanner; + + public GradeService() { + this.students = new Student[MAX_STUDENTS]; + this.scanner = new Scanner(System.in); + } + + public void addStudent() { + if (studentCount >= MAX_STUDENTS) { + System.out.println("Student limit reached."); + return; + } + + System.out.print("Enter student name: "); + String name = scanner.nextLine().trim(); + students[studentCount] = new Student(name, String.format("HYF-%03d", studentCount + 1)); + studentCount++; + System.out.println("Added."); + } + + public void enterGrades() { + System.out.print("Enter student ID: "); + Student student = findStudentById(scanner.nextLine().trim()); + if (student == null) { + System.out.println("Student not found."); + return; + } + + for (int i = 0; i < GradeUtils.MODULE_COUNT; i++) { + System.out.print("Enter grade for " + GradeUtils.MODULE_NAMES[i] + ": "); + student.setGrade(i, readInt()); + } + } + + public void viewAllStudents() { + if (studentCount == 0) { + System.out.println("No students yet."); + return; + } + + String border = "══════════════════════════════════════════════════════════════"; + + System.out.println(); + System.out.println(border); + System.out.printf(" %-10s %-20s %-9s %-7s %-6s%n", "ID", "NAME", "AVERAGE", "GRADE", "STATUS"); + System.out.println(border); + + int passing = 0; + for (int i = 0; i < studentCount; i++) { + Student student = students[i]; + double average = GradeUtils.calculateAverage(student.getGrades()); + if (GradeUtils.isPassing(average)) { + passing++; + } + System.out.printf(" %-10s %-20s %-9.2f %-7s %-6s%n", + student.getStudentId(), + student.getName(), + average, + GradeUtils.getLetterGrade(average), + GradeUtils.isPassing(average) ? "PASS" : "FAIL"); + } + + int failing = studentCount - passing; + System.out.println(border); + System.out.println(" Total students: " + studentCount + " Passing: " + passing + " Failing: " + failing); + System.out.println(border); + } + + public void viewStudentReport() { + System.out.print("Enter student ID: "); + Student student = findStudentById(scanner.nextLine().trim()); + if (student == null) { + System.out.println("Student not found."); + return; + } + + double average = GradeUtils.calculateAverage(student.getGrades()); + String separator = "══════════════════════════════════════"; + String dashedLine = "──────────────────────────────────────"; + + System.out.println(); + System.out.println(separator); + System.out.println(" STUDENT REPORT"); + System.out.println(separator); + System.out.println(" ID : " + student.getStudentId()); + System.out.println(" Name : " + student.getName()); + System.out.println(dashedLine); + System.out.println(" MODULE GRADES"); + System.out.println(dashedLine); + + int[] grades = student.getGrades(); + for (int i = 0; i < GradeUtils.MODULE_COUNT; i++) { + int grade = grades[i]; + String moduleName = GradeUtils.MODULE_NAMES[i]; + String status = GradeUtils.isModulePassing(grade) ? "PASS" : "FAIL"; + System.out.printf(" %-25s : %3d %s%n", moduleName, grade, status); + } + + System.out.println(dashedLine); + System.out.printf(" Average : %.2f%n", average); + System.out.println(" Grade : " + GradeUtils.getLetterGrade(average)); + String statusSymbol = GradeUtils.isPassing(average) ? "✓" : "✗"; + System.out.println(" Status : " + statusSymbol + " " + (GradeUtils.isPassing(average) ? "PASS" : "FAIL")); + System.out.println(separator); + } + + public void run() { + while (true) { + System.out.println(); + System.out.println("╔══════════════════════════════════════╗"); + System.out.println("║ HYF ACADEMY — GRADE MGR ║"); + System.out.println("╚══════════════════════════════════════╝"); + System.out.println(" 1. Add student"); + System.out.println(" 2. Enter grades"); + System.out.println(" 3. View all students"); + System.out.println(" 4. View student report"); + System.out.println(" 5. Exit"); + System.out.println("══════════════════════════════════════"); + System.out.print("Choose an option: "); + + + switch (readInt()) { + case 1 -> addStudent(); + case 2 -> enterGrades(); + case 3 -> viewAllStudents(); + case 4 -> viewStudentReport(); + case 5 -> { return; } + default -> System.out.println("Invalid option."); + } + } + } + + private Student findStudentById(String id) { + for (int i = 0; i < studentCount; i++) { + if (students[i].getStudentId().equalsIgnoreCase(id)) { + return students[i]; + } + } + return null; + } + + private int readInt() { + while (!scanner.hasNextInt()) { + scanner.nextLine(); + System.out.print("Enter a valid number: "); + } + + int value = scanner.nextInt(); + scanner.nextLine(); + return value; + } +} From cc4017e2a0ebe55f194ac66cd69ab910be01315b Mon Sep 17 00:00:00 2001 From: Miuroro Date: Thu, 7 May 2026 21:06:12 +0200 Subject: [PATCH 4/4] added The entry point to the application in Main.java --- task-1/com.hyfacademy/Main.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java index 49a03b1..0245083 100644 --- a/task-1/com.hyfacademy/Main.java +++ b/task-1/com.hyfacademy/Main.java @@ -1,6 +1,9 @@ +import com.hyfacademy.service.GradeService; + public class Main { public static void main(String[] args) { - System.out.println("Hello World!"); + GradeService service = new GradeService(); + service.run(); } }