Ex. Enter your grades: (user enters A B D F)
I need to read each letter separately and then give the user their gpa and a reply based on their gpa and grades.
If the user has less than for grades they are ineligible.
If the user has no F's and a GPA above 2.0 they are eligible.
If the user has an F and a GPA above 2.0 they are ineligible.
If the user has no F's but a GPA below 2.0 they are ineligible.
It the user has an F and a GPA below 2.0 they are ineligible.
this is what I have:
import chn.util.*;
class gpaTest
{
public static void main(String[] args)
{
int courses;
String grade;
int totalGrade;
double points;
char letterGrade;
totalGrade = 0;
points = 0.0;
ConsoleIO keyboard = new ConsoleIO();
//number of courses
System.out.print("Please enter the number of courses in which you are enrolled: ");
courses = keyboard.readInt();
System.out.println();
if(courses >= 4)
{
int counter1 = 0;
do
{
System.out.print("Please enter your grades: ");
grade = keyboard.readLine();
int counter2 = 0;
letterGrade = grade.charAt(counter2++);
switch (letterGrade)
{
case 'A': case 'a':
totalGrade += points + 4;
break;
case 'B': case 'b':
totalGrade += points + 3;
break;
case 'C': case 'c':
totalGrade += points + 2;
break;
case 'D': case 'd':
totalGrade += points + 1;
break;
case 'F': case 'f':
totalGrade += points + 0;
break;
default:
System.out.println("Invalid letter grade, try again.");
counter1--;
}
double GPA = (totalGrade / (double)courses);
if(GPA < 2.0 && (letterGrade != 'f' || letterGrade != 'F'))
{
System.out.println();
System.out.println("GPA = " + GPA + " Ineligible, gpa below 2.0");
System.out.println();
}
else if (GPA >= 2.0 && (letterGrade == 'f' || letterGrade == 'F'))
{
System.out.println();
System.out.println("GPA = " + GPA + " Ineligible, gpa above 2.0 but has F grade");
System.out.println();
}
else if (GPA < 2.0 && (letterGrade == 'f' || letterGrade == 'F'))
{
System.out.println();
System.out.println("GPA = " + GPA + " Ineligible, gpa below 2.0 and has F grade");
System.out.println();
}
else if (GPA >= 2.0 && letterGrade != 'f' || letterGrade != 'F')
{
System.out.println();
System.out.println("GPA = " + GPA + " Eligible");
System.out.println();
}
}while (counter1 <= courses);
}
else
{
System.out.print("Ineligible, taking less than 4 classes.");
}
}
}
*Edited [ code] tags added
This post has been edited by pbl: 11 January 2009 - 08:30 PM

New Topic/Question
Reply




MultiQuote




|