Final year grade calculator UK – Java Program

What it does:

A java program which is for final year UK students. It allows them to enter how many years they where at university. Upon entering how many years they have studied they will then then asked to enter the overall grades they achieved for each. Using if statements the program will then decide what grade they will be awarded using the general grading system from the UK. It will then print out what grade they should be awarded. At the end of the program they will be asked whether or not they would like to run the program again. This will be done through a do-while loop, as the program has to be run once but it is unknown how many times the user may choose to run it again. Once the user chooses to exit the program it will display a goodbye message.

Code:

public class UniversityFinalYearGradeUK
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int yearsStudied,runAgain;
        double gradesRecived, totalingGrades=0, grade;
        System.out.println("Welcome to the University Final year grading Program\n");

        do
        {
            //prompting user to enter yrs @ uni
            System.out.println("Please enter how many years you studied at University");
            //read in
            yearsStudied = keyboard.nextInt();

            for (int count =0; count<yearsStudied; count++)
            {
                System.out.println("Please enter the grade (percentage as a whole number) you received for year "+ (count+1));
                gradesRecived = keyboard.nextDouble();

                //creating a running total
                totalingGrades+=gradesRecived;

            }//for

            grade = totalingGrades/yearsStudied;

            //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();

            //restarting to 0
            gradesRecived=0;
            totalingGrades=0;
            yearsStudied =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