java - Why won't my main recognize what I returned? -
i can't program recognize eclassgpa , sclassgpa though returned them in methods. trying add of gpa's in main ones in separate methods. when 2 things returned create errors.
import java.util.scanner; public class gpa3 { public static void main(string[] args) { system.out.println("hello! welcome 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 a"); mathgpa = 4.0; system.out.println(mathgpa); } if (math < 94 && math >=90){ system.out.println("you have a-"); mathgpa = 3.7; system.out.println(mathgpa); } if (math < 90 && math >=87){ system.out.println("you have b+"); mathgpa = 3.3; system.out.println(mathgpa); } if (math < 87 && math >=80){ system.out.println("you have b"); mathgpa = 3.0; system.out.println(mathgpa); } if (math < 80 && math >=77){ system.out.println("you have b-"); mathgpa = 2.7; system.out.println(mathgpa); } if (math < 77 && math >=73){ system.out.println("you have c+"); mathgpa = 2.3; system.out.println(mathgpa); } if (math < 73 && math >=70){ system.out.println("you have c"); mathgpa = 2.0; system.out.println(mathgpa); } if (math < 70 && math >=67){ system.out.println("you have c-"); mathgpa = 1.7; system.out.println(mathgpa); } if (math < 67 && math >=67){ system.out.println("you have d+"); mathgpa = 1.3; system.out.println(mathgpa); } if (math < 67 && math >=63){ system.out.println("you have d"); mathgpa = 1.0; system.out.println(mathgpa); } if (math < 63 && math >=60){ system.out.println("you have d-"); mathgpa = 0.7; system.out.println(mathgpa); } if (math < 60){ system.out.println("you have 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 a"); englishgpa = 4.0; system.out.println(englishgpa); } if (english < 94 && english >=90){ system.out.println("you have a-"); englishgpa = 3.7; system.out.println(englishgpa); } if (english < 90 && english >=87){ system.out.println("you have b+"); englishgpa = 3.3; system.out.println(englishgpa); } if (english < 87 && english >=80){ system.out.println("you have b"); englishgpa = 3.0; system.out.println(englishgpa); } if (english < 80 && english >=77){ system.out.println("you have b-"); englishgpa = 2.7; system.out.println(englishgpa); } if (english < 77 && english >=73){ system.out.println("you have c+"); englishgpa = 2.3; system.out.println(englishgpa); } if (english < 73 && english >=70){ system.out.println("you have c"); englishgpa = 2.0; system.out.println(englishgpa); } if (english < 70 && english >=67){ system.out.println("you have c-"); englishgpa = 1.7; system.out.println(englishgpa); } if (english < 67 && english >=67){ system.out.println("you have d+"); englishgpa = 1.3; system.out.println(englishgpa); } if (english < 67 && english >=63){ system.out.println("you have d"); englishgpa = 1.0; system.out.println(englishgpa); } if (english < 63 && english >=60){ system.out.println("you have d-"); englishgpa = 0.7; system.out.println(englishgpa); } if (english < 60){ system.out.println("you have 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 a"); scigpa = 4.0; system.out.println(scigpa); } if (science < 94 && science >=90){ system.out.println("you have a-"); scigpa = 3.7; system.out.println(scigpa); } if (science < 90 && science >=87){ system.out.println("you have b+"); scigpa = 3.3; system.out.println(scigpa); } if (science < 87 && science >=80){ system.out.println("you have b"); scigpa = 3.0; system.out.println(scigpa); } if (science < 80 && science >=77){ system.out.println("you have b-"); scigpa = 2.7; system.out.println(scigpa); } if (science < 77 && science >=73){ system.out.println("you have c+"); scigpa = 2.3; system.out.println(scigpa); } if (science < 73 && science >=70){ system.out.println("you have c"); scigpa = 2.0; system.out.println(scigpa); } if (science < 70 && science >=67){ system.out.println("you have c-"); scigpa = 1.7; system.out.println(scigpa); } if (science < 67 && science >=67){ system.out.println("you have d+"); scigpa = 1.3; system.out.println(scigpa); } if (science < 67 && science >=63){ system.out.println("you have d"); scigpa = 1.0; system.out.println(scigpa); } if (science < 63 && science >=60){ system.out.println("you have d-"); scigpa = 0.7; system.out.println(scigpa); } if (science < 60){ system.out.println("you have 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 a"); spangpa = 4.0; system.out.println(spangpa); } if (spanish < 94 && spanish >=90){ system.out.println("you have a-"); spangpa = 3.7; system.out.println(spangpa); } if (spanish < 90 && spanish >=87){ system.out.println("you have b+"); spangpa = 3.3; system.out.println(spangpa); } if (spanish < 87 && spanish >=80){ system.out.println("you have b"); spangpa = 3.0; system.out.println(spangpa); } if (spanish < 80 && spanish >=77){ system.out.println("you have b-"); spangpa = 2.7; system.out.println(spangpa); } if (spanish < 77 && spanish >=73){ system.out.println("you have c+"); spangpa = 2.3; system.out.println(spangpa); } if (spanish < 73 && spanish >=70){ system.out.println("you have c"); spangpa = 2.0; system.out.println(spangpa); } if (spanish < 70 && spanish >=67){ system.out.println("you have c-"); spangpa = 1.7; system.out.println(spangpa); } if (spanish < 67 && spanish >=67){ system.out.println("you have d+"); spangpa = 1.3; system.out.println(spangpa); } if (spanish < 67 && spanish >=63){ system.out.println("you have d"); spangpa = 1.0; system.out.println(spangpa); } if (spanish < 63 && spanish >=60){ system.out.println("you have d-"); spangpa = 0.7; system.out.println(spangpa); } if (spanish < 60){ system.out.println("you have 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 a"); rgpa = 4.0; system.out.println(rgpa); } if (religion < 94 && religion >=90){ system.out.println("you have a-"); rgpa = 3.7; system.out.println(rgpa); } if (religion < 90 && religion >=87){ system.out.println("you have b+"); rgpa = 3.3; system.out.println(rgpa); } if (religion < 87 && religion >=80){ system.out.println("you have b"); rgpa = 3.0; system.out.println(rgpa); } if (religion < 80 && religion >=77){ system.out.println("you have b-"); rgpa = 2.7; system.out.println(rgpa); } if (religion < 77 && religion >=73){ system.out.println("you have c+"); rgpa = 2.3; system.out.println(rgpa); } if (religion < 73 && religion >=70){ system.out.println("you have c"); rgpa = 2.0; system.out.println(rgpa); } if (religion < 70 && religion >=67){ system.out.println("you have c-"); rgpa = 1.7; system.out.println(rgpa); } if (religion < 67 && religion >=67){ system.out.println("you have d+"); rgpa = 1.3; system.out.println(rgpa); } if (religion < 67 && religion >=63){ system.out.println("you have d"); rgpa = 1.0; system.out.println(rgpa); } if (religion < 63 && religion >=60){ system.out.println("you have d-"); rgpa = 0.7; system.out.println(rgpa); } if (religion < 60){ system.out.println("you have 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 have gym 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 a"); sclassgpa = 4.0; system.out.println(sclassgpa); } if (gym < 94 && gym >=90){ system.out.println("you have a-"); sclassgpa = 3.7; system.out.println(sclassgpa); } if (gym < 90 && gym >=87){ system.out.println("you have b+"); sclassgpa = 3.3; system.out.println(sclassgpa); } if (gym < 87 && gym >=80){ system.out.println("you have b"); sclassgpa = 3.0; system.out.println(sclassgpa); } if (gym < 80 && gym >=77){ system.out.println("you have b-"); sclassgpa = 2.7; system.out.println(sclassgpa); } if (gym < 77 && gym >=73){ system.out.println("you have c+"); sclassgpa = 2.3; system.out.println(sclassgpa); } if (gym < 73 && gym >=70){ system.out.println("you have c"); sclassgpa = 2.0; system.out.println(sclassgpa); } if (gym < 70 && gym >=67){ system.out.println("you have c-"); sclassgpa = 1.7; system.out.println(sclassgpa); } if (gym < 67 && gym >=67){ system.out.println("you have d+"); sclassgpa = 1.3; system.out.println(sclassgpa); } if (gym < 67 && gym >=63){ system.out.println("you have d"); sclassgpa = 1.0; system.out.println(sclassgpa); } if (gym < 63 && gym >=60){ system.out.println("you have d-"); sclassgpa = 0.7; system.out.println(sclassgpa); } if (gym < 60){ system.out.println("you have 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 a"); sclassgpa = 4.0; system.out.println(sclassgpa); } if (history < 94 && history >=90){ system.out.println("you have a-"); sclassgpa = 3.7; system.out.println(sclassgpa); } if (history < 90 && history >=87){ system.out.println("you have b+"); sclassgpa = 3.3; system.out.println(sclassgpa); } if (history < 87 && history >=80){ system.out.println("you have b"); sclassgpa = 3.0; system.out.println(sclassgpa); } if (history < 80 && history >=77){ system.out.println("you have b-"); sclassgpa = 2.7; system.out.println(sclassgpa); } if (history < 77 && history >=73){ system.out.println("you have c+"); sclassgpa = 2.3; system.out.println(sclassgpa); } if (history < 73 && history >=70){ system.out.println("you have c"); sclassgpa = 2.0; system.out.println(sclassgpa); } if (history < 70 && history >=67){ system.out.println("you have c-"); sclassgpa = 1.7; system.out.println(sclassgpa); } if (history < 67 && history >=67){ system.out.println("you have d+"); sclassgpa = 1.3; system.out.println(sclassgpa); } if (history < 67 && history >=63){ system.out.println("you have d"); sclassgpa = 1.0; system.out.println(sclassgpa); } if (history < 63 && history >=60){ system.out.println("you have d-"); sclassgpa = 0.7; system.out.println(sclassgpa); } if (history < 60){ system.out.println("you have 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 have 1 or 2 electives year?"); system.out.println("hint: write answers in word form"); input.nextline(); string 1 = "one"; string 2 = "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 a"); eclassgpa = 4.0; system.out.println(eclassgpa); } if (electiveone < 94 && electiveone >=90){ system.out.println("you have a-"); eclassgpa = 3.7; system.out.println(eclassgpa); } if (electiveone < 90 && electiveone >=87){ system.out.println("you have b+"); eclassgpa = 3.3; system.out.println(eclassgpa); } if (electiveone < 87 && electiveone >=80){ system.out.println("you have b"); eclassgpa = 3.0; system.out.println(eclassgpa); } if (electiveone < 80 && electiveone >=77){ system.out.println("you have b-"); eclassgpa = 2.7; system.out.println(eclassgpa); } if (electiveone < 77 && electiveone >=73){ system.out.println("you have c+"); eclassgpa = 2.3; system.out.println(eclassgpa); } if (electiveone < 73 && electiveone >=70){ system.out.println("you have c"); eclassgpa = 2.0; system.out.println(eclassgpa); } if (electiveone < 70 && electiveone >=67){ system.out.println("you have c-"); eclassgpa = 1.7; system.out.println(eclassgpa); } if (electiveone < 67 && electiveone >=67){ system.out.println("you have d+"); eclassgpa = 1.3; system.out.println(eclassgpa); } if (electiveone < 67 && electiveone >=63){ system.out.println("you have d"); eclassgpa = 1.0; system.out.println(eclassgpa); } if (electiveone < 63 && electiveone >=60){ system.out.println("you have d-"); eclassgpa = 0.7; system.out.println(eclassgpa); } if (electiveone < 60){ system.out.println("you have 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 a"); e1classgpa = 4.0; system.out.println(e1classgpa); } if (electiveone < 94 && electiveone >=90){ system.out.println("you have a-"); e1classgpa = 3.7; system.out.println(e1classgpa); } if (electiveone < 90 && electiveone >=87){ system.out.println("you have b+"); e1classgpa = 3.3; system.out.println(e1classgpa); } if (electiveone < 87 && electiveone >=80){ system.out.println("you have b"); e1classgpa = 3.0; system.out.println(e1classgpa); } if (electiveone < 80 && electiveone >=77){ system.out.println("you have b-"); e1classgpa = 2.7; system.out.println(e1classgpa); } if (electiveone < 77 && electiveone >=73){ system.out.println("you have c+"); e1classgpa = 2.3; system.out.println(e1classgpa); } if (electiveone < 73 && electiveone >=70){ system.out.println("you have c"); e1classgpa = 2.0; system.out.println(e1classgpa); } if (electiveone < 70 && electiveone >=67){ system.out.println("you have c-"); e1classgpa = 1.7; system.out.println(e1classgpa); } if (electiveone < 67 && electiveone >=67){ system.out.println("you have d+"); e1classgpa = 1.3; system.out.println(e1classgpa); } if (electiveone < 67 && electiveone >=63){ system.out.println("you have d"); e1classgpa = 1.0; system.out.println(e1classgpa); } if (electiveone < 63 && electiveone >=60){ system.out.println("you have d-"); e1classgpa = 0.7; system.out.println(e1classgpa); } if (electiveone < 60){ system.out.println("you have 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 a"); e2classgpa = 4.0; system.out.println(e2classgpa); } if (elective2 < 94 && elective2 >=90){ system.out.println("you have a-"); e2classgpa = 3.7; system.out.println(e2classgpa); } if (elective2 < 90 && elective2 >=87){ system.out.println("you have b+"); e2classgpa = 3.3; system.out.println(e2classgpa); } if (elective2 < 87 && elective2 >=80){ system.out.println("you have b"); e2classgpa = 3.0; system.out.println(e2classgpa); } if (elective2 < 80 && elective2 >=77){ system.out.println("you have b-"); e2classgpa = 2.7; system.out.println(e2classgpa); } if (elective2 < 77 && elective2 >=73){ system.out.println("you have c+"); e2classgpa = 2.3; system.out.println(e2classgpa); } if (elective2 < 73 && elective2 >=70){ system.out.println("you have c"); e2classgpa = 2.0; system.out.println(e2classgpa); } if (elective2 < 70 && elective2 >=67){ system.out.println("you have c-"); e2classgpa = 1.7; system.out.println(e2classgpa); } if (elective2 < 67 && elective2 >=67){ system.out.println("you have d+"); e2classgpa = 1.3; system.out.println(e2classgpa); } if (elective2 < 67 && elective2 >=63){ system.out.println("you have d"); e2classgpa = 1.0; system.out.println(e2classgpa); } if (elective2 < 63 && elective2 >=60){ system.out.println("you have d-"); e2classgpa = 0.7; system.out.println(e2classgpa); } if (elective2 < 60){ system.out.println("you have 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
to put @miltoxbeyond's answer context:
public static void main(string[] args){ // main method // end of religion double sclassgpa = answer(input); double eclassgpa = elective(input); double finalgrade = mathgpa + englishgpa+ scigpa+ sclassgpa + eclassgpa; }
Comments
Post a Comment