So im creating a gpa calculator, it takes the 4 classes (or more if i want) and calculates the letter grade and gpa weight.
How would i use the same method 4 times and each time have it add the different inputted variables.
For example, the first input of the first calling (for the grade) is an 80.
if i call it again and input a 90, I want it to store the inital 80 and add the 90 and so on so i can calculate the gpa.
Here is my code
import java.util.*;
public class GpaCalculator{
public static void main(String[] args) {
{
System.out.println("Please enter your name>>>");
Scanner stringinputs = new Scanner(System.in);
String name = stringinputs.nextLine();
GreatGrader();
System.out.println();
System.out.println(name);
}
}
public static void GreatGrader(){
Scanner stringinput = new Scanner(System.in);
System.out.println("Please enter your course>>>");
String Course1 = stringinput.nextLine();
System.out.println("What is the weight of this class? Normal, Honors, or AP?>>>");
String weight = stringinput.nextLine();
System.out.println("What is your grade in the class?>>>");
String grade = stringinput.nextLine();
double gpa = 0;
if (weight.equalsIgnoreCase("honors"))
gpa = gpa + 1;
else if (weight.equalsIgnoreCase("Ap"))
gpa = gpa + 1.5;
else if (weight.equalsIgnoreCase("normal"));
String letter;
Scanner in = new Scanner(System.in);
int grades = in.nextInt();
if (grades >= 96)
{ gpa = 4.5;
letter = "A";}
else if (grades >= 92)
{ gpa = 4.0;
letter = "A";}
else if (grades >=88 )
{ gpa = 3.5;
letter = "B"; }
else if (grades >= 84 )
{ gpa = 3.0;
letter = "B";}
else if (grades >=76 )
{ gpa = 2.5;
letter = "C";}
else if (grades >= 72)
{gpa = 1.5;
letter = "C";}
else if (grades>=68)
{ gpa = 1.0;
letter = "D";}
else if (grades <=67)
{ gpa = 0;
letter = "F";
}
}
}
Related
Can someone please tell me why my code is not providing the correct output? Here aare the instructions "
I need to write a program that reads student scores, gets the best
score, and then assigns grades based on the following scheme:
1) Grade is A if score is >= best - 10
2) Grade is B if score is >= best - 20;
3) Grade is C if score is >= best - 30;
4) Grade is D if score is >= best - 40;
5) Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. My problem comes from pulling the grades from an array, this is what I have so far:
// Here is my code. Thank You
import java.util.Scanner; // imports the scanner function
public class NBpractice { //class is formed
public static void main(String []args) { // main method
// user input is asked for the number of students
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentNum = input.nextInt();
//user input is asked for students scores
Scanner input2 = new Scanner(System.in);
System.out.print("Enter " + studentNum + " scores: ");
int scores = input2.nextInt();
int best = 80;
char letterGrade;
int scoresArray[] = new int[studentNum]; // array is created and holds the # of place values as students
for (int i = 0; i < scoresArray.length; i++) { // for loop created
scoresArray[i] = input2.nextInt(); //array values are assigned to user's input
best = scoresArray[0];
if (best < scoresArray[i]) {
best = scoresArray[i];
}
//-----------------------------------------------------------------------------
if (scores >= (best - 10)) {
letterGrade = 'A';
}
else if (scores >= (best - 20)) {
letterGrade = 'B';
}
else if (scores
>= (best - 30)) {
letterGrade = 'C';
}
else if (scores >= (best - 30)) {
letterGrade = 'D';
}
else {
letterGrade = 'F';
}
System.out.println("Student " + i + " Score is " + scoresArray[i] + " and grade is: " + letterGrade );
}
//------------------------------------------------------------
}
}
Some pointers...
This: System.out.print("Enter " + studentNum + " scores: "); and int scores = input2.nextInt(); need to go in the for loop body.
Use the for loop to populate the array.
Once that the for loop is executed, find the best (highest) score in the array.
Use another for loop to sort out the grades.
As is, your program will only ask for the grades and pretty much assumes that the best grade is 80, which might not always be the case.
You'll need two separate for loops. One to read the grades, and get the best, and the second for loop to normalize the grades.
int[] scores = new int[amount];
int best = -1;
for(int i = 0; i < amount; i++)
{
scores[i] = in.nextInt();
if(scores[i] > best)
best = scores[i];
}
System.out.println(Arrays.toString(scores));
// Now that we have the best, we can normalize
// the rest of the scores based on the best
// and assign the corresponding letter grade.
String[] grades = new String[amount];
for(int i = 0; i < amount; i++)
{
int score = scores[i] * 100 / best;
if(score >= 90)
grades[i] = "A";
else if(score >= 80)
grades[i] = "B";
else if(score >= 70)
grades[i] = "C";
else if(score >= 60)
grades[i] = "D";
else
grades[i] = "F";
scores[i] = score;
}
System.out.println(Arrays.toString(scores));
System.out.println(Arrays.toString(grades));
Test input 80 60 75 83 67 outputs:
[80, 60, 75, 83, 67]
[96, 72, 90, 100, 80]
[A, C, A, A, B]
I would recommend using a Student class and not work with parallel lists or arrays. A Student class can for example look like this:
class Student {
int score;
String grade; // could also be an Enum
public int getScore() {
return this.score;
}
public void setScore(int score) {
this.score = score;
}
public String getGrade() {
return this.grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
#Override
public String toString() {
return "Student{" + "score=" + score + ", grade='" + grade + '\'' + '}';
}
}
You can then make instance of the Students and add them to an ArrayList in you public static void main.
I think you have to use two loops because you cannot know beforehand what the best grade will be. In your main you can make enter the students add them to a List and compare their grades;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int highScore = 0;
int numOfStudent = input.nextInt();
List<Student> studentList = new ArrayList<>();
for (int i = 1; i <= numOfStudent; i++) { // you might want to add Exception handling here, by surrounding it with a try / catch or do more checks than only i <= numOfStudent
System.out.printf("please fill in the score of student no %d \n", i);
int score = input.nextInt();
Student student = new Student();
student.setScore(score);
if (score > highScore) {
highScore = score;
}
studentList.add(student);
}
System.out.println("these are the scores and grades of the Students");
for (Student s : studentList) {
if (s.getScore() >= highScore - 10) {
s.setGrade("A");
}
else if (s.getScore() >= highScore - 20) {
s.setGrade("B");
}
else if (s.getScore() >= highScore - 30) {
s.setGrade("C");
}
else if (s.getScore() >= highScore - 40) {
s.setGrade("D");
}
else {
s.setGrade("F");
}
System.out.println(s);
}
}
package Chapter7;
import java.util.Scanner;
public class Exercise7_1 {
public static void main(String[] args) {
// Assign grades
Scanner input = new Scanner(System.in);
int numStudents;
int[] scores;
int best;
System.out.println("Enter the number of students: ");
numStudents = input.nextInt();
scores = new int[numStudents];
System.out.println("Enter " + numStudents + " scores: ");
for (int i = 0; i < numStudents; i++) {
scores[i] = input.nextInt();
}
displayGrades(findBestScore(scores), scores);
}
public static int findBestScore(int[] scores) {
int best = scores[0];
for (int i = 1; i < scores.length-1; i++) {
if (scores[i] > best)
best = scores[i];
}
return best;
}
public static void displayGrades(int best, int[] scores ) {
char grade = ' ';
for (int i = 0; i < scores.length; i++) {
if (scores[i] >= best-10)
grade = 'A';
else if (best - 10 > scores[i] && scores[i] >= best - 20)
grade = 'B';
else if (best - 20 > scores[i] && scores[i] >= best -30)
grade = 'C';
else if (best - 30 > scores[i] && scores[i] >= best -40)
grade = 'D';
else if (best - 40 > scores[i])
grade = 'F';
System.out.println("Student " + i + " score is " + scores[i] + " and grade is " + grade);
}
}
}
This program basically calculates the gpa, by letting the user enter the number of courses and course code, with the relevant credit and marks. If the course code is entered twice, a message will show (the course is already registered), and it will keep looping until the user has entered all courses with a different course code
I have created two methods. One to check if the code is already registered and the other for calculating the gpa, the first method that checks the user input, I'm not sure about it. Because if I entered the course code twice it will only show the message and would allow me to calculate the rest
public static boolean checkCourse(String[] courseList, String code){
boolean check = false;
for(int i=0 ; i < courseList.length; i++){
if(code.equals(courseList[i]))
check = true;
else
check = false;
}
return check;
}
public static double gradeValue(double marks){
double grade = 1.0;
if(marks >=95){ grade = 5.0;}
else if (marks >= 90) { grade = 4.75;}
else if (marks>=85) { grade = 4.5;}
else if (marks >= 80) { grade = 4.0;}
else if (marks >= 75) { grade = 3.5; }
else if (marks >= 70) { grade = 3.0;}
else if (marks >= 65) {grade = 2.5 ;}
else if (marks >= 60) { grade = 2;}
else if (marks < 60) { grade =1 ;}
return grade;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of courses: ");
int n = input.nextInt();
String[] Courses = new String[n];
int sumOfcreadit=0;
int sumOfmarks =0;
for(int i =0; i<Courses.length;i++){
System.out.print("Enter a course code: ");
Courses[i] = input.next();
if(checkCourse(Courses,Courses[i])){
System.out.println("the course already registered");
i--;
}
System.out.print("Enter a credit: ");
int credit = input.nextInt();
System.out.print(" Enter a marks: ");
int marks = input.nextInt();
sumOfcreadit += credit;
sumOfmarks +=marks * credit;
}
double TotalMarks;
TotalMarks = sumOfmarks /sumOfcreadit;
System.out.println("The GPA is: "+gradeValue(TotalMarks));
}
I made some changes in your code and now it works. Changes are described in below code. There was 3 important changes.
I tried to make as less changes as possible to make your code work as expected
public static boolean checkCourse(String[] courseList, String code) {
boolean check = false;
for (int i = 0; i < courseList.length; i++) {
if (code.equals(courseList[i])) { // equals instead of == to compare strings
check = true;
break; // you have to break loop if it is true because else statement before returned false even if there was the same course code due to null values in next array elements which was not filled yet
}
}
return check;
}
public static double gradeValue(double marks) {
double grade = 1.0;
if (marks >= 95) {
grade = 5.0;
} else if (marks >= 90) {
grade = 4.75;
} else if (marks >= 85) {
grade = 4.5;
} else if (marks >= 80) {
grade = 4.0;
} else if (marks >= 75) {
grade = 3.5;
} else if (marks >= 70) {
grade = 3.0;
} else if (marks >= 65) {
grade = 2.5;
} else if (marks >= 60) {
grade = 2;
} else if (marks < 60) {
grade = 1;
}
return grade;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of courses: ");
int n = input.nextInt();
String[] Courses = new String[n];
int sumOfcreadit = 0;
int sumOfmarks = 0;
for (int i = 0; i < Courses.length; i++) {
System.out.print("Enter a course code: ");
String code = input.next();
if (checkCourse(Courses, code)){
System.out.println("the course already regestered ");
i--;
continue; // continue is neccessary to let user write value again if it already exists
}
Courses[i] = code;
System.out.print("Enter a credit: ");
int credit = input.nextInt();
System.out.print(" Enter a marks: ");
int marks = input.nextInt();
sumOfcreadit += credit;
sumOfmarks += marks * credit;
}
double TotalMarks;
TotalMarks = sumOfmarks / sumOfcreadit;
System.out.println("The GPA is: " + gradeValue(TotalMarks));
}
Use a set kind of structure to store all the course code visited, It will avoid unnecessary iteration on your course array
this method can be enhanced to
public static boolean checkCourse(HashSet<String> courses, String code){
boolean check = false;
if(courses.contains(code)){
check = true;
else
check = false;
}
return check;
}
Initialise the hashset courses and if the checkCourses method returns false add the course code in courses.
Initialize before loop like this
HashSet<String> courseSet = new HashSet<String>();
your if condition inside loop
if(checkCourse(courseSet,courses[i])){ // check for variable name , name should always start with lower case letter
System.out.println("the course already regestered ");
i--;
// You can use continue if you don't want processing for it
// it will skip the loop iteration and it will go next iteration
}else{
courseSet.add(courses[i]);
}
I barely started coding a couple weeks ago and have a project for my high school computer science class that requires me to make a GPA calculator. It's not the best code right now or the best technique to calculate GPA but it's a start (if someone could help clean it up and simplify it I would greatly appreciate you).
There's a problem with the code though. Every time a user input is required from the console they have to press enter twice. I feel like the solution is very easy but I am stuck on why this is happening.
import java.util.Scanner;
public class gpaCalc {
public static double gpa;
public static String grade = "";
public static double gpaTotal = 0;
public static double points = 0;
public static double numberOfClasses;
public static double class1points;
public static double class2points;
public static double class3points;
public static double class4points;
public static double class5points;
public static double class6points;
public static double class7points;
public static double class8points;
static Scanner letterGrade = new Scanner(System.in);
static Scanner numClasses = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Welcome to Adrian's GPA calculator.");
System.out.println("This program will calculate your weighted and unweighted GPA for this school year.");
classesNumber();
}
public static void classesNumber() {
System.out.println("Please enter the number of classes that you are enrolled in for the school year.");
numberOfClasses = numClasses.nextDouble(); //input is stored in variable numberOfClasses
if(numberOfClasses >= 9 || numberOfClasses < 2)
System.out.println("Are you sure you go to ECHS?");
//limit the number of classes from 2-8
if (numberOfClasses <= 8 && numberOfClasses >= 2)
System.out.println("Please enter the letter grade you have recieved in class 1 (Uppercase letters i.e. A,B,C,D,F).");
else
classesNumber(); //error occurs and doesn't reset when a letter is put and not a number
class1();
}
public static void class1() {
grade = letterGrade.next(); //unweighted GPA finder
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class1 ();
}
class1points = points;
class2();
}
public static void class2() {
System.out.println("Please enter the letter grade you have recieved in class 2 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class2();
}
class2points = points;
class3();
}
public static void class3() {
System.out.println("Please enter the letter grade you have recieved in class 3 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class3();
}
class3points = points;
class4();
}
public static void class4() {
System.out.println("Please enter the letter grade you have recieved in class 4 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class4();
}
class4points = points;
class5();
}
public static void class5() {
System.out.println("Please enter the letter grade you have recieved in class 5 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class5();
}
class5points = points;
class6();
}
public static void class6() {
System.out.println("Please enter the letter grade you have recieved in class 6 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class6();
}
class6points = points;
class7();
}
public static void class7() {
System.out.println("Please enter the letter grade you have recieved in class 7 (Uppercase letters i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class7();
}
class7points = points;
class8();
}
public static void class8() {
System.out.println("Please enter the letter grade you have recieved in class 8 (Uppercase letter i.e. A,B,C,D,F).");
grade = letterGrade.next();
if (grade.equals("A"))
points = 4.0;
else if (grade.equals("B"))
points = 3.0;
else if (grade.equals("C"))
points = 2.0;
else if (grade.equals("D"))
points = 1.0;
else if (grade.equals("F"))
points = 0;
else {
System.out.println("Invalid entry. Please enter a valid entry.");
class8();
}
class8points = points;
calculator();
}
public static void calculator() {
gpaTotal = (class1points + class2points + class3points + class4points + class5points + class6points + class7points + class8points ) / numberOfClasses;
System.out.println("Your unwweighted GPA is: " + gpaTotal);
}
}
Your problem should be solved by removing 1 scanner, and suggestions to your codes :
Use array to store subjects
String[] mySubjects = {"sub_1", "sub_2", "sub_3", "sub_4", ..};
Use loop to reduce repetitive
for (int i = 0; i < mySubject.length; i++) {
your_code_here;
}
Created a simplified version of your code, without need for an array.
Maybe not the best, but if you just started out, it can guide you somewhere about avoiding code repetition.
I tried to organize everything the way you did, just to help you see the code more clearly.
Maybe you can add a plus check to this code, in the classNumber() method, to avoid entering non integer values. + Split the getClassPoints() method into some parts to avoid side effects..
public static char grade;
public static double gpaTotal = 0;
public static int numberOfClasses;
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Welcome to Adrian's GPA calculator.");
System.out.println("This program will calculate your weighted and unweighted GPA for this school year.");
classesNumber();
}
public static void classesNumber() {
System.out.println("Please enter the number of classes that you are enrolled in for the school year.");
numberOfClasses = scan.nextInt(); //input is stored in variable numberOfClasses
if(numberOfClasses >= 9 || numberOfClasses < 2)
System.out.println("Are you sure you go to ECHS?");
getClassPoints();
}
public static void getClassPoints () {
//You dont need the numberOfClasses as parameter because its static.
for (int i = 0; i < numberOfClasses; i++){
while (true){
System.out.println("Please enter the letter grade you have recieved in class " + (i + 1) +"(Uppercase letter i.e. A,B,C,D,F).");
grade = scan.next().charAt(0); //unweighted GPA finder
grade = Character.toLowerCase(grade);
if (grade == 'a'){
gpaTotal += 4;
break;
}
else if (grade == 'b'){
gpaTotal += 3;
break;
}
else if (grade == 'c'){
gpaTotal += 2;
break;
}
else if (grade == 'd'){
gpaTotal += 1;
break;
}
else if (grade == 'f'){
break;
}
System.out.println("Invalid entry. Please enter a valid entry.");;
}
}
if (gpaTotal > 0){
System.out.println("Your unwweighted GPA is: " + (gpaTotal / numberOfClasses));
}
else {
System.out.println("Too many F grade!");
}
}
}
I'm trying to write a code to convert a letter grade to a numerical value. I have this code but when I run it, I get an error saying java.lang.StringIndexOutOfBoundsException.
What am I doing wrong?
Here is the code:
import java.util.Scanner;
public class Lab6Smalls {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String grade;
String letter1;
String letter2;
double gpa = 0;
System.out.print("Enter a letter grade: ");
grade = scan.nextLine();
letter1 = grade.substring(0,1);
letter2 = grade.substring(1,2);
if (letter1.equals("A") && letter2.equals("+")){
gpa = 4.3;
} else if (letter1.equals("A")){
gpa = 4.0;
} else if (letter1.equals("B")){
gpa = 3.0;
} else if (letter1.equals("C")){
gpa = 2.0;
} else if (letter1.equals("D")){
gpa = 1.0;
} else if (letter1.equals("F")){
gpa = 0.0;
} else {
System.out.println("The value is invalid.");
}
if (!letter1.equals("F")){
if(letter2.equals("+") && !letter1.equals("A")) gpa += 0.3;
else if(letter2.equals("-")) gpa -= 0.3;
}
System.out.println("The numerical value is " + gpa + ".");
}
}
There is an error because alphabets other than A+ do not have a second value
A+ has two letters
B has one so when you try to find a second, it breaks
C has one so when you try to find a second, it breaks
D has one so when you try to find a second, it breaks
You want to check if the second value exists, before you retrieve it.
Try this
String letter2 = "";
grade = scan.nextLine();
letter1 = grade.substring(0,1);
// Check, if there is a second letter, get it.
if (grade.length() >= 2) {
letter2 = grade.substring(1,2);
}
Before you substring(1, 2) you should make sure the length > 1.
The following is what you want.
import java.util.Scanner;
public class Lab6Smalls {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String grade;
double gpa;
System.out.print("Enter a letter grade: ");
grade = scan.nextLine();
if (null == grade || "".equals(grade)) {
System.out.println("The value is invalid.");
return;
}
switch (grade.substring(0, 1)) {
case "A":
gpa = 4.0;
break;
case "B":
gpa = 3.0;
break;
case "C":
gpa = 2.0;
break;
case "D":
gpa = 1.0;
break;
case "F":
gpa = 0.0;
break;
default:
System.out.println("The value is invalid. : " + grade);
return;
}
if (grade.length() > 1) {
String letter2 = grade.substring(1, 2);
if ("+".equals(letter2)) {
gpa += 0.3;
} else if ("-".equals(letter2)) {
gpa -= 0.3;
}
}
System.out.println("The numerical value is " + gpa + ".");
}
}
I'm trying to make a class where you input any number of grades (A-F) and calculates the GPA and returns the GPA and eligibility to extracurricular activities. It seems like the scanner only allows one input, then prints the GPA and eligibility.
So far this is what I have:
import java.util.Scanner;
public class Grades
{
public static void main(String[] args)
{
double myGPA;
int myNumClasses;
double myValue;
Scanner sc = new Scanner(System.in);
System.out.println("Press any other lettter to calculate.");
System.out.print("Enter grades: ");
String input = sc.nextLine();
myValue = 0;
myNumClasses = 0;
myGPA = 0;
for (String next = sc.next(); input.equalsIgnoreCase("a") || input.equalsIgnoreCase("b") ||
input.equalsIgnoreCase("c")|| input.equalsIgnoreCase("d") || input.equalsIgnoreCase("f"); next = sc.next())
{
if (input.equalsIgnoreCase("a"))
{
myValue += 4.0;
myNumClasses += 1;
}
else if (input.equalsIgnoreCase("b"))
{
myValue += 3.0;
myNumClasses += 1;
}
else if (input.equalsIgnoreCase("c"))
{
myValue += 2.0;
myNumClasses += 1;
}
else if (input.equalsIgnoreCase("d"))
{
myValue += 1.0;
myNumClasses += 1;
}
else if (input.equalsIgnoreCase("f"))
{
myNumClasses += 1;
}
myGPA = myValue / myNumClasses;
if (myGPA >= 2.0 && myNumClasses >= 4)
{
System.out.println("Eligible");
}
else if (myNumClasses < 4)
{
System.out.println("Ineligible, taking less than 4 classes");
}
else if (myGPA >= 2.0 && input.equalsIgnoreCase("f"))
{
System.out.println("Ineligible, gpa above 2.0 but has F grade");
}
else if (myGPA <= 2.0 && input.equalsIgnoreCase("f"))
{
System.out.println("Ineligible, gpa below 2.0 and has F grade");
}
else if (myGPA < 2.0)
{
System.out.println("Inelligible, gpa below 2.0");
}
System.out.println("Your GPA = " + myGPA);
}
}
}
// It looks like your missing a for loop. I just copied some of your
//code and ran it through a for loop. The rest of the code is kind of unclear.
System.out.println("Enter the number of grades you will enter: ");
int userAns = sc.nextInt();
for (int index = 0; index <= userAns; index++)
{
System.out.println("Press any other letter to calculate.");
System.out.print("Enter grades: ");
String input = sc.nextLine();
}