Package com.project

Class GradeCalculator

java.lang.Object
com.project.GradeCalculator

public class GradeCalculator extends Object
The GradeCalculator class calculates the grades of students based on their marks.

It takes input for the number of subjects, accepts marks for each subject, calculates the total and average marks, and assigns a grade based on predefined ranges.

The program also handles invalid inputs and allows the user to calculate grades repeatedly until they choose to exit.

Version:
1.0.0
Author:
Anurag Zete
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static enum 
    Enum representing the grade system based on marks ranges.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static double
    Stores the calculated average marks.
    private static final Scanner
    Scanner object for reading user input.
    private static double
    Stores the cumulative total marks of all subjects.
    private static int
    Stores the total number of subjects entered by the user.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static double
    calculateGrade(Scanner sc, int totalSubjects)
    Accepts marks for each subject and calculates the total marks.
    private static void
    Displays the final results, including: Total marks obtained out of the maximum possible marks. Average marks calculated. The grade obtained based on the average.
    static void
    main(String[] args)
    The main method to run the grade calculator program.
    private static void
    Runs the grade calculation program loop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sc

      private static final Scanner sc
      Scanner object for reading user input.
    • totalMarks

      private static double totalMarks
      Stores the cumulative total marks of all subjects.
    • totalSubjects

      private static int totalSubjects
      Stores the total number of subjects entered by the user.
    • averageMarks

      private static double averageMarks
      Stores the calculated average marks.
  • Constructor Details

    • GradeCalculator

      public GradeCalculator()
  • Method Details

    • main

      public static void main(String[] args)
      The main method to run the grade calculator program.

      It displays a banner, starts the grade calculation loop, and exits the program when the user chooses to stop.

      Parameters:
      args - Command-line arguments (not used).
    • program

      private static void program()
      Runs the grade calculation program loop.

      - Prompts the user for the number of subjects.
      - Calls the calculateGrade() method to accept marks.
      - Displays the result using displayResult().
      - Allows the user to repeat the grade calculation or exit.

    • calculateGrade

      private static double calculateGrade(Scanner sc, int totalSubjects)
      Accepts marks for each subject and calculates the total marks.

      - Marks are stored in an array for validation purposes.
      - Accepts "ab" or empty input as an indicator of absence (assigns 0.0).
      - Ensures valid marks range (0 - 100) and handles incorrect input formats.

      Parameters:
      sc - The Scanner object for user input.
      totalSubjects - The total number of subjects.
      Returns:
      The cumulative total marks.
    • displayResult

      private static void displayResult()
      Displays the final results, including:
      • Total marks obtained out of the maximum possible marks.
      • Average marks calculated.
      • The grade obtained based on the average.