CalculateGPA

4
CalculateGPA /* * Filename: "CalculateGPA.java" * Created by 1,000_naymes for ICT 352 * * Purpose: to calculate the GPA for the semester. * */ import java.util.Scanner; import javax.swing.JOptionPane; public class CalculateGPA { public static void main ( String[] args ) { String grade, A, B, C, D, F, X, stringA = "A", stringB = "B", stringC = "C", stringD = "D", stringF = "F", stringX = "X", outputStr; int choice = 0, N = 0, sum = 0, i = 0, total = 0; double gradePoints = 0, gradePoints2 = 0, gradePoints3 = 0, gradePoints4 = 0; char choiceChar; double GPA = 0; Scanner input = new Scanner( System.in ); boolean sameA, sameB, sameC, sameD, sameF, sameX; System.out.print( "Welcome to the student GPA program, \n which will compute student grades for you.\n" ); System.out.print( "\nPlease enter student letter grade for Biology 201 (A, B, C, D, F) \nor X to quit:" ); grade = input.nextLine(); if( sameA = grade.equalsIgnoreCase(stringA)) choice = 65; if( sameB = grade.equalsIgnoreCase(stringB)) choice = 66; if( sameC = grade.equalsIgnoreCase(stringC)) choice = 67; if( sameD = grade.equalsIgnoreCase(stringD)) choice = 68; if( sameF = grade.equalsIgnoreCase(stringF)) choice = 69; if( sameX = grade.equalsIgnoreCase(stringX)) choice = 88; switch( choice ) { case 65: gradePoints = 4; N++; break; case 66: gradePoints = 3; N++; break; case 67: gradePoints = 2; N++; break; case 68: Page 1

Transcript of CalculateGPA

Page 1: CalculateGPA

CalculateGPA/* * Filename: "CalculateGPA.java" * Created by 1,000_naymes for ICT 352 ** Purpose: to calculate the GPA for the semester. * */

import java.util.Scanner;import javax.swing.JOptionPane;

public class CalculateGPA{ public static void main ( String[] args ) {

String grade, A, B, C, D, F, X, stringA = "A", stringB = "B", stringC = "C", stringD = "D", stringF = "F", stringX = "X", outputStr;

int choice = 0, N = 0, sum = 0, i = 0, total = 0; double gradePoints = 0, gradePoints2 = 0, gradePoints3 = 0, gradePoints4 =

0;char choiceChar;double GPA = 0;

Scanner input = new Scanner( System.in );boolean sameA, sameB, sameC, sameD, sameF, sameX;

System.out.print( "Welcome to the student GPA program, \n which will computestudent grades for you.\n" );

System.out.print( "\nPlease enter student letter grade for Biology 201 (A, B, C, D, F) \nor X to quit:" );

grade = input.nextLine();

if( sameA = grade.equalsIgnoreCase(stringA))choice = 65;

if( sameB = grade.equalsIgnoreCase(stringB))choice = 66;

if( sameC = grade.equalsIgnoreCase(stringC))choice = 67;

if( sameD = grade.equalsIgnoreCase(stringD))choice = 68;

if( sameF = grade.equalsIgnoreCase(stringF))choice = 69;

if( sameX = grade.equalsIgnoreCase(stringX))choice = 88;

switch( choice ){ case 65:

gradePoints = 4;N++;break;

case 66: gradePoints = 3;N++;break;

case 67: gradePoints = 2;N++;break;

case 68: Page 1

Page 2: CalculateGPA

CalculateGPAgradePoints = 1;N++; break;

case 69: gradePoints = 0;N++;break;

case 88:GPA = ( gradePoints + gradePoints2 + gradePoints3 + gradePoints4 ) /

N;System.out.print( "Your student's GPA is " + GPA + "." );break;

}sum = N;

System.out.print( "\nPlease enter student letter grade for Chemistry 222 (A,B, C, D, F) \nor X to quit:" );

grade = input.nextLine();

if( sameA = grade.equalsIgnoreCase(stringA))choice = 65;

if( sameB = grade.equalsIgnoreCase(stringB))choice = 66;

if( sameC = grade.equalsIgnoreCase(stringC))choice = 67;

if( sameD = grade.equalsIgnoreCase(stringD))choice = 68;

if( sameF = grade.equalsIgnoreCase(stringF))choice = 69;

if( sameX = grade.equalsIgnoreCase(stringX))choice = 88;

switch( choice ){ case 65:

gradePoints2 = 4;N++;break;

case 66: gradePoints2 = 3;N++;break;

case 67: gradePoints2 = 2;N++;break;

case 68: gradePoints2 = 1;N++; break;

case 69: gradePoints2 = 0;N++;break;

case 88:GPA = ( gradePoints + gradePoints2 + gradePoints3 + gradePoints4 ) /

Page 2

Page 3: CalculateGPA

CalculateGPAN;

System.out.print( "Your student's GPA is " + GPA + "." );break;

}

System.out.print( "\nPlease enter student letter grade for Math 163 (A, B, C, D, F) \nor X to quit:" );

grade = input.nextLine();

if( sameA = grade.equalsIgnoreCase(stringA))choice = 65;

if( sameB = grade.equalsIgnoreCase(stringB))choice = 66;

if( sameC = grade.equalsIgnoreCase(stringC))choice = 67;

if( sameD = grade.equalsIgnoreCase(stringD))choice = 68;

if( sameF = grade.equalsIgnoreCase(stringF))choice = 69;

if( sameX = grade.equalsIgnoreCase(stringX))choice = 88;

switch( choice ){ case 65:

gradePoints3 = 4;N++;break;

case 66: gradePoints3 = 3;N++;break;

case 67: gradePoints3 = 2;N++;break;

case 68: gradePoints3 = 1;N++; break;

case 69: gradePoints3 = 0;N++;break;

case 88:GPA = ( gradePoints + gradePoints2 + gradePoints3 + gradePoints4 ) /

N;System.out.print( "Your student's GPA is " + GPA + "." );break;

}

System.out.print( "\nPlease enter student letter grade for Computer Science 255 (A, B, C, D, F) \nor X to quit:" );

grade = input.nextLine();

if( sameA = grade.equalsIgnoreCase(stringA))choice = 65;

if( sameB = grade.equalsIgnoreCase(stringB))Page 3

Page 4: CalculateGPA

CalculateGPAchoice = 66;

if( sameC = grade.equalsIgnoreCase(stringC))choice = 67;

if( sameD = grade.equalsIgnoreCase(stringD))choice = 68;

if( sameF = grade.equalsIgnoreCase(stringF))choice = 69;

if( sameX = grade.equalsIgnoreCase(stringX))choice = 88;

switch( choice ){ case 65:

gradePoints4 = 4;N++;break;

case 66: gradePoints4 = 3;N++;break;

case 67: gradePoints4 = 2;N++;break;

case 68: gradePoints4 = 1;N++; break;

case 69: gradePoints4 = 0;N++;break;

case 88:GPA = ( gradePoints + gradePoints2 + gradePoints3 + gradePoints4 ) /

N;System.out.print( "Your student's GPA is " + GPA + "." );break;

} GPA = ( gradePoints + gradePoints2 + gradePoints3 + gradePoints4 ) /N;

System.out.print( "Your student's GPA is " + GPA + ".") ;

return;

}}

Page 4