Student GPA

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

StudentGPA

/*
* Filename: "StudentGPA.java"
* Created by 1,000_naymes for ICT 352
*
* Purpose: to calculate GPA for a student based on input from the user.
*
*/

import javax.swing.JOptionPane;

public class StudentGPA


{
public static void main( String[] args )
{
/**************************************************************
declare and initialize variables
**************************************************************/
String openingMessage,
gradeInputMessage, gradeString, listMessage,
menu, quitMessage = "Goodbye.",
choiceInputMessage, choiceString, GPAMessage, finalGrade,
string4 = "A", string3 = "B", string2 = "C", string1 = "D", string0 =
"F",
byeString = "Q", list;

int choice, GPA = 0, grade = 0, number, i = 0;


/**************************************************************
display opening message
**************************************************************/
openingMessage = "Welcome to the student GPA program, \nwhich will calculate
the GPA of a student\n based on your entry of their most recent letter grades.";
JOptionPane.showMessageDialog( null, openingMessage );
choiceInputMessage = "Enter \n"
+ "1 to continue and enter student grades\n"
+ "2 to quit \n";
choiceString = JOptionPane.showInputDialog( choiceInputMessage );
choice = Integer.parseInt( choiceString ); //converting string to integer

switch( choice )
{
case 1:
do
{
Boolean stringsAreEqual;
gradeInputMessage = "Please enter a letter grade for the student (A, B,
C, D, or F)\n or Q to quit.";
gradeString = JOptionPane.showInputDialog( gradeInputMessage );
if( stringsAreEqual = gradeString.equalsIgnoreCase( string4 ) )
grade = 4;
if( stringsAreEqual = gradeString.equalsIgnoreCase( string3 ) )
grade = 3;
if( stringsAreEqual = gradeString.equalsIgnoreCase( string2 ) )
grade = 2;
if( stringsAreEqual = gradeString.equalsIgnoreCase( string1 ) )
grade = 1;
if( stringsAreEqual = gradeString.equalsIgnoreCase( string0 ) )
Page 1
StudentGPA
grade = 0;
if( stringsAreEqual = gradeString.equalsIgnoreCase( byeString) )
break;
int total = i + 1;
GPA = grade / total;
}
while( gradeString != "X" );
GPAMessage = "Their overall GPA is a " + GPA + ".0";
JOptionPane.showMessageDialog( null, GPAMessage );

list = " " + grade;


listMessage = "Your student's grades were " + list;
JOptionPane.showMessageDialog( null, listMessage );

case 2:
quitMessage = "Goodbye.";
JOptionPane.showMessageDialog( null, quitMessage );

}
System.exit(0);
}

Page 2

You might also like