java - GPA Calculator Error - Variable might not been initialized? -


can please me through problem ?

/* author: m asad raza date: 18/03/2014 */  code:-  import java.util.scanner;      class gpacalculator {          public static void main(string args[]) {             scanner input = new scanner(system.in);              double sub1,sub2,sub3,sub4,sub5,sub6,subtotal=100*6,obtained,gp;             double gp1,gp2,gp3,gp4,gp5,gp6;             string name;                     system.out.println("   \n***welcome gpa calculator***\n");                 system.out.print("enter name: ");                 name=input.nextline();                 system.out.println("\n**hello "+name+" :)\n");                 system.out.print("enter subject#1 marks: ");                 sub1=input.nextint();                 if(sub1>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub1<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                 system.out.print("enter subject#2 marks: ");                 sub2=input.nextint();                 if(sub2>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub2<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                 system.out.print("enter subject#3 marks: ");                 sub3=input.nextint();                 if(sub3>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub3<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                 system.out.print("enter subject#4 marks: ");                 sub4=input.nextint();                 if(sub4>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub4<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                 system.out.print("enter subject#5 marks: ");                 sub5=input.nextint();                 if(sub5>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub5<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                 system.out.print("enter subject#6 marks: ");                 sub6=input.nextint();                 if(sub6>100){                 system.out.println("marks exceeded limit.\ntry agian..!!");                 system.exit(0);                 }                 if(sub6<45){                 system.out.println("subject failed!!\ngpa can't calculated.");                 system.exit(0);                 }                  //calculating gpa                 if(sub1>=85&&sub1<=100) {                 gp1=4.00;                 }                  if(sub1>=80&&sub1<=84) {                 gp1=3.70;                 }                 if(sub1>=75&&sub1<=79) {                 gp1=3.30;                 }                 if(sub1>=70&&sub1<=74) {                 gp1=3.00;                 }                 if(sub1>=65&&sub1<=69) {                 gp1=2.70;                 }                 if(sub1>=60&&sub1<=64) {                 gp1=2.30;                 }                 if(sub1>=55&&sub1<=59) {                 gp1=2.00;                 }                 if(sub1>=50&&sub1<=54) {                 gp1=1.70;                 }                 if(sub1>=45&&sub1<=49) {                 gp1=1.00;                 }                 //*****sub1 gp1 finished                 if(sub2>=85&&sub2<=100) {                 gp2=4.00;                 }                 if(sub2>=80&&sub2<=84) {                 gp2=3.70;                 }                 if(sub2>=75&&sub2<=79) {                 gp2=3.30;                 }                 if(sub2>=70&&sub2<=74) {                 gp2=3.00;                 }                 if(sub2>=65&&sub2<=69) {                 gp2=2.70;                 }                 if(sub2>=60&&sub2<=64) {                 gp2=2.30;                 }                 if(sub2>=55&&sub2<=59) {                 gp2=2.00;                 }                 if(sub2>=50&&sub2<=54) {                 gp2=1.70;                 }                 if(sub2>=45&&sub2<=49) {                 gp2=1.00;                 }                 //***** sub2 gp2 finished                 if(sub3>=85&&sub3<=100) {                 gp3=4.00;                 }                 if(sub3>=80&&sub3<=84) {                 gp3=3.70;                 }                 if(sub3>=75&&sub3<=79) {                 gp3=3.30;                 }                 if(sub3>=70&&sub3<=74) {                 gp3=3.00;                 }                 if(sub3>=65&&sub3<=69) {                 gp3=2.70;                 }                 if(sub3>=60&&sub3<=64) {                 gp3=2.30;                 }                 if(sub3>=55&&sub3<=59) {                 gp3=2.00;                 }                 if(sub3>=50&&sub3<=54) {                 gp3=1.70;                 }                 if(sub3>=45&&sub3<=49) {                 gp3=1.00;                 }                 //*****sub3 gp3 finished                 if(sub4>=85&&sub4<=100) {                 gp4=4.00;                 }                 if(sub4>=80&&sub4<=84) {                 gp4=3.70;                 }                 if(sub4>=75&&sub4<=79) {                 gp4=3.30;                 }                 if(sub4>=70&&sub4<=74) {                 gp4=3.00;                 }                 if(sub4>=65&&sub4<=69) {                 gp4=2.70;                 }                 if(sub4>=60&&sub4<=64) {                 gp4=2.30;                 }                 if(sub4>=55&&sub4<=59) {                 gp4=2.00;                 }                 if(sub4>=50&&sub4<=54) {                 gp4=1.70;                 }                 if(sub4>=45&&sub4<=49) {                 gp4=1.00;                 }                 //*****gp4 sub4 finished                 if(sub5>=85&&sub5<=100) {                 gp5=4.00;                 }                 if(sub5>=80&&sub5<=84) {                 gp5=3.70;                 }                 if(sub5>=75&&sub5<=79) {                 gp5=3.30;                 }                 if(sub5>=70&&sub5<=74) {                 gp5=3.00;                 }                 if(sub5>=65&&sub5<=69) {                 gp5=2.70;                 }                 if(sub5>=60&&sub5<=64) {                 gp5=2.30;                 }                 if(sub5>=55&&sub5<=59) {                 gp5=2.00;                 }                 if(sub5>=50&&sub5<=54) {                 gp5=1.70;                 }                 if(sub5>=45&&sub5<=49) {                 gp5=1.00;                 }                 //***** sub5 gp5 finished                 if(sub6>=85&&sub6<=100) {                 gp6=4.00;                 }                 if(sub6>=80&&sub6<=84) {                 gp6=3.70;                 }                 if(sub6>=75&&sub6<=79) {                 gp6=3.30;                 }                 if(sub6>=70&&sub6<=74) {                 gp6=3.00;                 }                 if(sub6>=65&&sub6<=69) {                 gp6=2.70;                 }                 if(sub6>=60&&sub6<=64) {                 gp6=2.30;                 }                 if(sub6>=55&&sub6<=59) {                 gp6=2.00;                 }                 if(sub6>=50&&sub6<=54) {                 gp6=1.70;                 }                 if(sub6>=45&&sub6<=49) {                 gp6=1.00;                 }                  //end calculating gpa                  obtained=sub1+sub2+sub3+sub4+sub5+sub6;                 gp=gp1+gp2+gp3+gp4+gp5+gp6;                 gp=gp/6;                 system.out.println("\n\n******information******\n");                 system.out.println("total marks = "+subtotal+"\n"+"obtained marks = "+obtained+"\n"+"percentage = "+(obtained/subtotal)*100);                 system.out.println("gpa = "+gp);                 system.out.println("\n***********************");          }            } 

without further knowledge ( error example ... ) first guess line culprit.

double sub1,sub2,sub3,sub4,sub5,sub6,subtotal=100*6,obtained,gp; 

i think setting sub1,sub2,sub3,sub4,sub5,sub6 & subtotal 600, , leaving obtained , gp uninitialised. ( it's uncommon looking line of code )

if that's case, then

double gp1,gp2,gp3,gp4,gp5,gp6; 

is leaving these variable uninitialised.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -