jeudi 5 juillet 2018

Java if statement not working

In my code I'm trying to make an if statement to have my final grades be equal to my theory and or practical if 1 or both of them are below 50%. If both are under 50%, the lowest one needs to equal the final grade. NOTE: I put a lot brackets in the code that i cannot get working if this helps.

My Code:

import java.text.DecimalFormat;
import java.util.Scanner;

public class GradeCalculator {
private double lab = 0;
private double quiz = 0; 
private double assignment = 0; 
private double midterm = 0; 
private double exam1 = 0; 
private double theory = 0;
private double practical = 0;
private double final_grade = 0;
private double grade_letter = 0;
private Scanner keys = new Scanner(System.in);


public GradeCalculator(){
    System.out.println("Welcome to the CST8215 Final Mark Calculator\n");
}

public void getMarks() {
    System.out.print("Enter your Lab mark out of 10: ");
    lab = keys.nextDouble();

    System.out.print("Enter your Quiz/Test mark out of 10: ");
    quiz = keys.nextDouble();

    System.out.print("Enter your Assignment mark out of 20: ");
    assignment = keys.nextDouble();

    System.out.print("Enter your Midterm mark out of 20: ");
    midterm = keys.nextDouble();

    System.out.print("Enter your Final Exam mark out of 40: ");
    exam1 = keys.nextDouble();

}

public void calculateGrades() {
    theory =((quiz + midterm + exam1)/70)*100;
    practical =((assignment+lab)/30)*100;
    final_grade =((lab+quiz+assignment+midterm+exam1)/100)*100; 
    grade_letter =((lab+quiz+assignment+midterm+exam1)/100)*100;    

}

public void displayGrades() {
    DecimalFormat number = new DecimalFormat ("##.##");
    System.out.print("\nTheory grade: "+number.format(theory)+ "%");
    System.out.print("\nPractical grade: "+number.format(practical)+ "%");
    System.out.print("\nFinal grade: "+number.format(final_grade)+ "%");
    System.out.print("\nGrade Letter: ");


    (((((   if(theory < 50 ) {
            final_grade = theory;
           }
            else if (practical < 50)
            final_grade = practical;   ))))))


        if(grade_letter < 60) {
        System.out.print("F");

     } else if (grade_letter >= 60 && grade_letter < 62.99) {
         System.out.print("C-");

     } else if (grade_letter >= 63 && grade_letter < 66.99) {
         System.out.print("C");

     } else if (grade_letter >= 67 && grade_letter < 69.99) {
         System.out.print("C+");

     } else if (grade_letter >= 70 && grade_letter < 72.99) {
         System.out.print("B-");

     } else if (grade_letter >= 73 && grade_letter < 76.99) {
         System.out.print("B");

     } else if (grade_letter >= 77 && grade_letter < 79.99) {
         System.out.print("B+");

     } else if (grade_letter >= 80 && grade_letter < 84.99) {
         System.out.print("A-");

     } else if (grade_letter >= 85 && grade_letter < 89.99) {
         System.out.print("A");

     } else if (grade_letter >= 90 && grade_letter < 100) {
         System.out.print("A+");

    } 

}
}

Aucun commentaire:

Enregistrer un commentaire