ASSIGNMENT 8

import javax.swing.JOptionPane; 

public class GPA {
    public static void main(String[] args)
    {
        String  firstNumber,  //the first number imputed
                secondNumber, //the second number imputed
                thirdNumber,  //the third number imputed
                fourthNumber, //the fourth number imputed
                fifthNumber;  //the fifth number imputed
 
 //the numbers to be used in the calculations
       double course1,       
            course2,       
            course3,
            course4,
            course5,
            theA = 4.0,
            gpa;        
         //getting imput from the user
        firstNumber = JOptionPane.showInputDialog("Enter % in the first course:");
        secondNumber =JOptionPane.showInputDialog("Enter % in the second course:");
        thirdNumber = JOptionPane.showInputDialog("Enter % in the third course:");
        fourthNumber = JOptionPane.showInputDialog("Enter % in the fourth course:");
        fifthNumber = JOptionPane.showInputDialog("Enter % in the fifth course:");
        
        //changing the imput from characters to integers.
        course1 = Integer.parseInt(firstNumber);
        course2 = Integer.parseInt(secondNumber);
        course3 = Integer.parseInt(thirdNumber);
        course4 = Integer.parseInt(fourthNumber);
        course5 = Integer.parseInt(fifthNumber);

        //the GPA calculation 
        gpa = theA * (((course1 +  course2 +  course3 +  course4 +  course5)/5)/100);
           
      //the output
       JOptionPane.showMessageDialog(
           null, "Your GPA is " + gpa, "Results",
           JOptionPane.PLAIN_MESSAGE);
     System.exit(0); 
      }
}
Hosted by www.Geocities.ws

1