University grading program UK – Java

What it does:

A Java program which allows the user to calculate their grade after entering their exam marks, it’s based on the UK grading system. It allows the user to choose how many modules they have taken per university year or semester. It however assumes all modules are out of 100. At the end of the program it will display which grade the user has received and prompt to see if they would like run the program again. If they don’t it will display a goodbye message.

Code:

public class UniversityGradingUK
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int modulesTaken, multiplyingModules, runAgain;
        double gradesReceived = 0, totalOfGrades = 0, grade;

        //welcome
        System.out.println("Welcome the the University Grading program\n");
        System.out.println("This program will only accept percentages");

        do
        {
            //prompt
            System.out.println("Please enter how many modules you took this year");
            //read
            modulesTaken = keyboard.nextInt();

            //loop imputing grades
            for(int count =0; count<modulesTaken; count++)
            {
                System.out.println("Please enter the grades(percentages) you received for module " + (count+1));
                gradesReceived = keyboard.nextDouble();

                totalOfGrades+=gradesReceived;
            }//for

            //calculations
            multiplyingModules = modulesTaken*100;

            grade = totalOfGrades/multiplyingModules*100;

            //finding out what class they are in
            if(grade >= 70)
            {
                System.out.println("Your total grade (percentage) is " + grade);
                System.out.println("You have received a first");
            }//if

            else if(grade >= 60)
            {
                System.out.println("Your total grade (percentage) is " + grade);
                System.out.println("You have received a 2:1");
            }//else if

            else if(grade >= 50)
            {
                System.out.println("Your total grade (percentage) is " + grade);
                System.out.println("You have received a 2:2");
            }//else if

            else if(grade >=40)
            {
                System.out.println("Your total grade (percentage) is " + grade);
                System.out.println("You have received pass");
            }//else if

            else
            {
                System.out.println("Your total grade (percentage) is " + grade);
                System.out.println("Sorry to tell you but you've failed");
            }//else

            //prompting user to see whether or not they would like to run the program again
            System.out.println("Would you like to run the program again");
            System.out.println("1. Yes");
            System.out.println("2. No");

            //read in
            runAgain = keyboard.nextInt();

            //resetting variables to 0
            gradesReceived = 0;
            totalOfGrades = 0;
            grade=0;

        }//do


        //condition to keep running while user chooses yes
        while (runAgain!=2);

        System.out.println("You've chosen to exit. Goodbye for now!");

    }//main
}//class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s