2015-07-01 122 views
0

即使我在他們的方法中返回它們,我也無法讓我的程序識別eClassGpa和sClassGpa。我試圖用單獨的方法將所有的GPA與主要的GPA相加。當我這樣做時,我返回的兩件事情會產生錯誤。爲什麼我的主人不知道我回來了什麼?

import java.util.Scanner; 
public class GPA3 { 

    public static void main(String[] args) 
    { 
     System.out.println("Hello! Welcome to the GPA Calculator."); 

     int Math; 
     double mathGpa = 0; 

     System.out.println("Math = "); 
     Scanner input = new Scanner(System.in); 
     Math= input.nextInt(); 

     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 = 0.0; 
      System.out.println(mathGpa); 
     }//End of Math 

     int English; 
     double englishGpa = 0; 
     System.out.println("English = "); 
     English= input.nextInt(); 

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

     int Science; 
     double SciGpa = 0; 
     System.out.println("Science = "); 
     Science= input.nextInt(); 

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

     int Spanish; 
     double SpanGpa = 0; 
     System.out.println("Spanish = "); 
     Spanish= input.nextInt(); 

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

     int Religion; 
     double RGpa = 0; 
     System.out.println("Religion = "); 
     Religion= input.nextInt(); 

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

     double finalGrade; 
     finalGrade= mathGpa + englishGpa+ SciGpa+ sClassGpa + eClassGpa; 


    }//End of Main 

    public static double answer(Scanner input) 
     {//Begin answer 
     double sClassGpa=0; 
     System.out.println("Do you have gym this semester?"); 
     input.nextLine(); 
     String yes = "yes"; 
     String no = "no"; 
     String answer = input.nextLine(); 

     if (answer.equals(yes)){ 
      int Gym; 
      System.out.println("Gym = "); 
      Gym= input.nextInt(); 
      if (Gym >100){ 
       System.out.println("You have mistyped something"); 
      } 
      if (Gym >= 94 && Gym < 101){ 
       System.out.println("You have an A"); 
       sClassGpa = 4.0; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 94 && Gym >=90){ 
       System.out.println("You have an A-"); 
       sClassGpa = 3.7; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 90 && Gym >=87){ 
       System.out.println("You have a B+"); 
       sClassGpa = 3.3; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 87 && Gym >=80){ 
       System.out.println("You have a B"); 
       sClassGpa = 3.0; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 80 && Gym >=77){ 
       System.out.println("You have a B-"); 
       sClassGpa = 2.7; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 77 && Gym >=73){ 
       System.out.println("You have a C+"); 
       sClassGpa = 2.3; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 73 && Gym >=70){ 
       System.out.println("You have a C"); 
       sClassGpa = 2.0; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 70 && Gym >=67){ 
       System.out.println("You have a C-"); 
       sClassGpa = 1.7; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 67 && Gym >=67){ 
       System.out.println("You have a D+"); 
       sClassGpa = 1.3; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 67 && Gym >=63){ 
       System.out.println("You have a D"); 
       sClassGpa = 1.0; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 63 && Gym >=60){ 
       System.out.println("You have a D-"); 
       sClassGpa = 0.7; 
       System.out.println(sClassGpa); 
      } 
      if (Gym < 60){ 
       System.out.println("You have a F"); 
       sClassGpa = 0.0; 
       System.out.println(sClassGpa); 
      } 
     }//End Gym 

     if (answer.equals(no)){ 
      int History; 
      System.out.println("History = "); 
      History= input.nextInt(); 

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

     return (sClassGpa); 
    }//End answer 

    public static double elective(Scanner input) 
    {//Begin answer 
    double eClassGpa=0; 
    System.out.println("Do you have one or two electives this year?"); 
    System.out.println("Hint: write answers in word form"); 
    input.nextLine(); 
    String one = "one"; 
    String two = "two"; 
    String elective = input.nextLine(); 

    if (elective.equals(one)){ 
     int electiveOne; 
     System.out.println("Elective 1 = "); 
     electiveOne= input.nextInt(); 
     if (electiveOne >100){ 
      System.out.println("You have mistyped something"); 
     } 
     if (electiveOne >= 94 && electiveOne < 101){ 
      System.out.println("You have an A"); 
      eClassGpa = 4.0; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 94 && electiveOne >=90){ 
      System.out.println("You have an A-"); 
      eClassGpa = 3.7; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 90 && electiveOne >=87){ 
      System.out.println("You have a B+"); 
      eClassGpa = 3.3; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 87 && electiveOne >=80){ 
      System.out.println("You have a B"); 
      eClassGpa = 3.0; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 80 && electiveOne >=77){ 
      System.out.println("You have a B-"); 
      eClassGpa = 2.7; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 77 && electiveOne >=73){ 
      System.out.println("You have a C+"); 
      eClassGpa = 2.3; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 73 && electiveOne >=70){ 
      System.out.println("You have a C"); 
      eClassGpa = 2.0; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 70 && electiveOne >=67){ 
      System.out.println("You have a C-"); 
      eClassGpa = 1.7; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 67 && electiveOne >=67){ 
      System.out.println("You have a D+"); 
      eClassGpa = 1.3; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 67 && electiveOne >=63){ 
      System.out.println("You have a D"); 
      eClassGpa = 1.0; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 63 && electiveOne >=60){ 
      System.out.println("You have a D-"); 
      eClassGpa = 0.7; 
      System.out.println(eClassGpa); 
     } 
     if (electiveOne < 60){ 
      System.out.println("You have a F"); 
      eClassGpa = 0.0; 
      System.out.println(eClassGpa); 
     } 


    }//End Elective 1 

    if(elective.equals(two)){ 

     double e1ClassGpa=0; 
     double e2ClassGpa=0; 

     if (elective.equals(two)){ 
      int electiveOne; 
      System.out.println("Elective 1 = "); 
      electiveOne= input.nextInt(); 
      if (electiveOne >100){ 
       System.out.println("You have mistyped something"); 
      } 
      if (electiveOne >= 94 && electiveOne < 101){ 
       System.out.println("You have an A"); 
       e1ClassGpa = 4.0; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 94 && electiveOne >=90){ 
       System.out.println("You have an A-"); 
       e1ClassGpa = 3.7; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 90 && electiveOne >=87){ 
       System.out.println("You have a B+"); 
       e1ClassGpa = 3.3; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 87 && electiveOne >=80){ 
       System.out.println("You have a B"); 
       e1ClassGpa = 3.0; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 80 && electiveOne >=77){ 
       System.out.println("You have a B-"); 
       e1ClassGpa = 2.7; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 77 && electiveOne >=73){ 
       System.out.println("You have a C+"); 
       e1ClassGpa = 2.3; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 73 && electiveOne >=70){ 
       System.out.println("You have a C"); 
       e1ClassGpa = 2.0; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 70 && electiveOne >=67){ 
       System.out.println("You have a C-"); 
       e1ClassGpa = 1.7; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 67 && electiveOne >=67){ 
       System.out.println("You have a D+"); 
       e1ClassGpa = 1.3; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 67 && electiveOne >=63){ 
       System.out.println("You have a D"); 
       e1ClassGpa = 1.0; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 63 && electiveOne >=60){ 
       System.out.println("You have a D-"); 
       e1ClassGpa = 0.7; 
       System.out.println(e1ClassGpa); 
      } 
      if (electiveOne < 60){ 
       System.out.println("You have a F"); 
       e1ClassGpa = 0.0; 
       System.out.println(e1ClassGpa); 
      } 

     }//End Elective 1 

     int elective2; 
     System.out.println("Elective 2 = "); 
     elective2= input.nextInt(); 

     if (elective2 >100){ 
      System.out.println("You have mistyped something"); 
     } 
     if (elective2 >= 94 && elective2 <101){ 
      System.out.println("You have an A"); 
      e2ClassGpa = 4.0; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 94 && elective2 >=90){ 
      System.out.println("You have an A-"); 
      e2ClassGpa = 3.7; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 90 && elective2 >=87){ 
      System.out.println("You have a B+"); 
      e2ClassGpa = 3.3; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 87 && elective2 >=80){ 
      System.out.println("You have a B"); 
      e2ClassGpa = 3.0; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 80 && elective2 >=77){ 
      System.out.println("You have a B-"); 
      e2ClassGpa = 2.7; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 77 && elective2 >=73){ 
      System.out.println("You have a C+"); 
      e2ClassGpa = 2.3; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 73 && elective2 >=70){ 
      System.out.println("You have a C"); 
      e2ClassGpa = 2.0; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 70 && elective2 >=67){ 
      System.out.println("You have a C-"); 
      e2ClassGpa = 1.7; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 67 && elective2 >=67){ 
      System.out.println("You have a D+"); 
      e2ClassGpa = 1.3; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 67 && elective2 >=63){ 
      System.out.println("You have a D"); 
      e2ClassGpa = 1.0; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 63 && elective2 >=60){ 
      System.out.println("You have a D-"); 
      e2ClassGpa = 0.7; 
      System.out.println(e2ClassGpa); 
     } 
     if (elective2 < 60){ 
      System.out.println("You have a F"); 
      e2ClassGpa = 0.0; 
      System.out.println(e2ClassGpa); 
     }//End of Elective 2 
     eClassGpa= e1ClassGpa + e2ClassGpa; 
     }//End of ElectiveTwo 
    input.close(); 
    return (eClassGpa); 
    }//End of Elective 

}//End of Class 
+1

它看起來像sClassGpa和eClassGpa正在main()中使用,但它們從未在任何地方聲明或分配。 – amza

+0

只需要清楚,sClassGpa和eClassGpa是什麼? – Aleksandar

+0

sClassGpa和eClassGpa在其各自的功能中被分配爲局部變量,但您期望它們是類變量。將它們移出課程級別,它們將在班級中可見。請注意,它們仍然對主體不可見,因爲您從未實例化過GPA3 – KevinDTimm

回答

0

你調用的方法electiveanswer沒有結果存儲到一個變量。

您應該使用一個變量來存儲結果:

sClassGpa= answer(input); 
eClassGpa = elective(input); 

你應該意識到,你的函數中創建的,雖然他們有相同名稱的局部變量是不一樣的,你在聲明的那些主要功能。這就是爲什麼你必須將你的函數的結果存儲在一個變量中,如果你想使用它們。

編輯

需要明確的是:你應該把這些線路對你的主要方法

 }//End of Religion 
     answer(input); //Edit this line... 
     elective(input); //And this line 

     double finalGrade; 
     finalGrade= mathGpa + englishGpa+ SciGpa+ sClassGpa + eClassGpa; 
}//End of Main 
+0

你把這些代碼放在哪裏? – user5071017

0

年底把@ MiltoxBeyond的答案的來龍去脈:

public static void main(String[] args){ 

    // your main method 
    // End of Religion 

    double sClassGpa = answer(input); 
    double eClassGpa = elective(input); 

    double finalGrade = mathGpa + englishGpa+ SciGpa+ sClassGpa + eClassGpa; 
} 
相關問題