lundi 29 juin 2015

How to insert doubles into the main method?

I am trying to write a program that calculates my math and English GPA. I can't get the main to recognize my two floats, mathGpa and englishGpa. It tells me to make them static but making them static means that they become strings and I need them to remain doubles.

import java.util.Scanner;
public class GPA {

    public static void main(String[] args)
    {
        double finalGpa=0;

        mathGpa();
        englishGpa();

        finalGpa= (mathGpa + englishGpa)/2;


    }

    public double mathGpa() {//Begin mathGpa
        int Math;
        double mathGpa = 0;
        System.out.println("Math = ");
        Scanner math = new Scanner(System.in);
        Math= math.nextInt();
        math.close();

        if (Math >100){
            System.out.println("You have mistyped something");
        }
        if (Math >= 94){
            System.out.println("You have an A");
            mathGpa = 4.0;
            System.out.println(mathGpa);
        }
        if (Math < 94 && Math >=90){
            System.out.println("You have an A-");
            mathGpa = 3.7;
            System.out.println(mathGpa);
        }
        if (Math < 90 && Math >=87){
            System.out.println("You have a B+");
            mathGpa = 3.3;
            System.out.println(mathGpa);
        }
        if (Math < 87 && Math >=80){
            System.out.println("You have a B");
            mathGpa = 3.0;
            System.out.println(mathGpa);
        }
        if (Math < 80 && Math >=77){
            System.out.println("You have a B-");
            mathGpa = 2.7;
            System.out.println(mathGpa);
        }
        if (Math < 77 && Math >=73){
            System.out.println("You have a C+");
            mathGpa = 2.3;
            System.out.println(mathGpa);
        }
        if (Math < 73 && Math >=70){
            System.out.println("You have a C");
            mathGpa = 2.0;
            System.out.println(mathGpa);
        }
        if (Math < 70 && Math >=67){
            System.out.println("You have a C-");
            mathGpa = 1.7;
            System.out.println(mathGpa);
        }
        if (Math < 67 && Math >=67){
            System.out.println("You have a D+");
            mathGpa = 1.3;
            System.out.println(mathGpa);
        }
        if (Math < 67 && Math >=63){
            System.out.println("You have a D");
            mathGpa = 1.0;
            System.out.println(mathGpa);
        }
        if (Math < 63 && Math >=60){
            System.out.println("You have a D-");
            mathGpa = 0.7;
            System.out.println(mathGpa);
        }
        if (Math < 60){
            System.out.println("You have a F");
            mathGpa = 1.7;
            System.out.println(mathGpa);
        }

        return mathGpa;
    }//End mathGpa

    public double englishGpa() {//Begin englishGpa
        int English;
        double englishGpa = 0;
        System.out.println("English = ");
        Scanner english = new Scanner(System.in);
        English= english.nextInt();
        english.close();

        if (English >100){
            System.out.println("You have mistyped something");
        }
        if (English >= 94){
            englishGpa = 4.0;
        }
        if (English < 94 && English >=90){
            englishGpa = 3.7;
        }
        if (English < 90 && English >=87){
            englishGpa = 3.3;
        }
        if (English < 87 && English >=80){
            englishGpa = 3.0;
        }
        if (English < 80 && English >=77){
            englishGpa = 2.7;
        }
        if (English < 77 && English >=73){
            englishGpa = 2.3;
        }
        if (English < 73 && English >=70){
            englishGpa = 2.0;
        }
        if (English < 70 && English >=67){
            englishGpa = 1.7;
        }
        if (English < 67 && English >=67){
            englishGpa = 1.3;
        }
        if (English < 67 && English >=63){
            englishGpa = 1.0;
        }
        if (English < 63 && English >=60){
            englishGpa = 0.7;
        }
        if (English < 60){
            englishGpa = 1.7;
        }

        return englishGpa;
    }//End englishGpa

}//End Class

Aucun commentaire:

Enregistrer un commentaire