When the final grade is above 200, i want an error message to show up but it doesn't, i tried to structure my loop that way but it just doesnt work.
import java.util.Scanner;
import java.util.Formatter;
public class Lab3 {
public static void main(String[] args) {
double midtermGrade = 50.0;
double homeworkGrade = 0.0;
double finalExamGrade = 50.0;
double finalGrade = 0.0;
char letterGrade = ' ';
Scanner scan = new Scanner(System.in);
System.out.println("Enter homework grade: ");
homeworkGrade = scan.nextDouble();
System.out.println("Enter midterm exam grade: ");
midtermGrade = scan.nextDouble();
System.out.println("Enter final exam grade: ");
finalExamGrade = scan.nextDouble();
if ((!(homeworkGrade >= 0) || !(homeworkGrade <= 100))) return;
if (((midtermGrade >= 0) && (midtermGrade <= 100)))
if ((((!(finalExamGrade > 0) || !(finalExamGrade < 200))))) {
finalGrade = (finalExamGrade / 200) * 50 + (midtermGrade * .25) + (homeworkGrade * .25); //.25 denotes 25%
}
System.out.println("Invalid input. Homework and midterm grades should be between 0 and 100 and the final grade should be between 0 and 200");
if (finalGrade >= 50) {
letterGrade = 'P';
} else if (finalGrade < 50) {
letterGrade = 'F';
}
if (letterGrade == 'P') {
System.out.println("Student passed the class");
} else if (letterGrade == 'F') {
System.out.println("Student failed the class");
}
}
}
When i put the obnoxiously large numbers, i don't get any message. The debug ends.
Aucun commentaire:
Enregistrer un commentaire