P. 1
StudentGPA

StudentGPA

|Views: 17|Likes:
Published by api-3812198
Loop asks for letter grades, converts to grade points & calculates GPA until user enters X to quit... then displays final GPA.
Loop asks for letter grades, converts to grade points & calculates GPA until user enters X to quit... then displays final GPA.

More info:

Published by: api-3812198 on Oct 17, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

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 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 (A, B, ) ) ) ) )

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're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->