Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By doWhile

Thread: Variable numeric might now have been initialized

  1. #1
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Variable numeric might now have been initialized

    I think everything is fine but there is always this error saying "variable numeric might not have been initialized"
    Java Code:
    import java.util.*;
    public class GRADINGSYSTEM
    {
    public static void main(String [] args)
    {
    double seatwork,assignment,exam,attendance,quiz,overall,prelim,midterm,prefi,finals,ctrA,ctrB,numeric;
    String answer,A="y",B="Y",C="c",D="C",name,lastname,middlename,condition;
    Scanner Input = new Scanner(System.in);
    System.out.println("Greetings! Stranger! Inorder for us to know you, please type some of your personal information that we will be asking for you.");
    System.out.println("");
    System.out.println("Please Type your LASTNAME: ");
    lastname = Input.nextLine();
    System.out.println("Please Type your NAME: ");
    name = Input.nextLine();
    System.out.println("Please Type your MIDDLEINITIAL: ");
    middlename = Input.nextLine();
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " This is a program that is made by Group2, and we really appriciate your participation with us. This is for computing GRADES! So please give us the right information we'll be asking from you.");
    System.out.println("");
    System.out.println("Type 'Y' for YES/yes and press ENTER if your ready else type 'C' for CANCEL/cancel and press Enter if your not ready yet. WARNING: Entering another words or numbers that isn't asking will cause this program to END.");
    System.out.println("");
    answer = Input.next();
    if(answer.equals(C)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(D)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(A)){
    System.out.println("");
    System.out.println("Great! Now we can Start. First of PRELIM GRADES.");
    } else if(answer.equals(B)){
    System.out.println("");
    System.out.println("Great! Now we can Start. First of PRELIM GRADES.");
    } else{
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " your action had cost us to end this program please read the warning message carefully before using our program - Group2");
    return;
    }
    System.out.println("");
    System.out.println("Enter your overall Exercise score: ");
    seatwork = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Assignment score: ");
    assignment = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Quiz score: ");
    quiz = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Exam score: ");
    exam = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Attendance: ");
    attendance = Input.nextDouble();
    System.out.println("");
    System.out.println("Okay GREAT! We are done with your PRELIM grades!");
    System.out.println("");
    prelim = (seatwork*.10)+(attendance*.05)+(quiz*.15)+(exam*.20)+50;
    
    System.out.println("Type 'Y' for YES/yes and press ENTER if your ready else type 'C' for CANCEL/cancel and press Enter if your not ready yet. WARNING: Entering another words or numbers that isn't asking will cause this program to END.");
    System.out.println("");
    answer = Input.next();
    if(answer.equals(C)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(D)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(A)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Second is MIDTERM GRADES.");
    } else if(answer.equals(B)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Second is MIDTERM GRADES.");
    } else{
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " your action had cost us to end this program please read the warning message carefully before using our program - Group2");
    return;
    }
    System.out.println("");
    System.out.println("Enter your overall Exercise score: ");
    seatwork = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Assignment score: ");
    assignment = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Quiz score: ");
    quiz = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Exam score: ");
    exam = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Attendance: ");
    attendance = Input.nextDouble();
    System.out.println("");
    System.out.println("Okay GREAT! We are done with your MIDTERM grades!");
    System.out.println("");
    midterm = (seatwork*.10)+(attendance*.05)+(quiz*.15)+(exam*.20)+50;
    
    System.out.println("Type 'Y' for YES/yes and press ENTER if your ready else type 'C' for CANCEL/cancel and press Enter if your not ready yet. WARNING: Entering another words or numbers that isn't asking will cause this program to END.");
    System.out.println("");
    answer = Input.next();
    if(answer.equals(C)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(D)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(A)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Third is Prefinals GRADES.");
    } else if(answer.equals(B)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Third is Prefinals GRADES.");
    } else{
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " your action had cost us to end this program please read the warning message carefully before using our program - Group2");
    return;
    }
    System.out.println("");
    System.out.println("Enter your overall Exercise score: ");
    seatwork = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Assignment score: ");
    assignment = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Quiz score: ");
    quiz = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Exam score: ");
    exam = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Attendance: ");
    attendance = Input.nextDouble();
    System.out.println("");
    System.out.println("Okay GREAT! We are done with your PREFINAL grades!");
    System.out.println("");
    prefi = (seatwork*.10)+(attendance*.05)+(quiz*.15)+(exam*.20)+50;
    
    System.out.println("Type 'Y' for YES/yes and press ENTER if your ready else type 'C' for CANCEL/cancel and press Enter if your not ready yet. WARNING: Entering another words or numbers that isn't asking will cause this program to END.");
    System.out.println("");
    answer = Input.next();
    if(answer.equals(C)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(D)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(A)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Last but not least FINALS GRADES.");
    } else if(answer.equals(B)){
    System.out.println("");
    System.out.println("Great! Now we can Start. Last but not least FINALS GRADES.");
    } else{
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " your action had cost us to end this program please read the warning message carefully before using our program - Group2");
    return;
    }
    System.out.println("");
    System.out.println("Enter your overall Exercise score: ");
    seatwork = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Assignment score: ");
    assignment = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your overall Quiz score: ");
    quiz = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Exam score: ");
    exam = Input.nextDouble();
    System.out.println("");
    System.out.println("Enter your Attendance: ");
    attendance = Input.nextDouble();
    System.out.println("");
    System.out.println("Okay GREAT! We are done with your FINALS grades! and now we are about to reveal your grade weather if your fail or pass.");
    System.out.println("");
    finals = (seatwork*.10)+(attendance*.05)+(quiz*.15)+(exam*.40)+50;
    overall = (prelim*.2)+(midterm*.2)+(prefi*.2)+(finals*.4);
    System.out.println("");
    System.out.println("You ready " +lastname+ ", " +name+ " " +middlename+ "." + "? If so type 'Y' for YES/yes and press ENTER if your ready else type 'C' for CANCEL/cancel and press Enter if your not ready yet. WARNING: Entering another words or numbers that isn't asking will cause this program to END.");
    if(answer.equals(C)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(D)){
    System.out.println("");
    System.out.println("You have successfully canceled the session.");
    return;
    } else if(answer.equals(A)){
    if(overall<=74){
    numeric = 5;
    } else if(overall<=79){
    numeric = 3;
    } else if(overall<=84){
    numeric = 2.5;
    } else if(overall<=90){
    numeric = 2;
    } else if(overall<=95){
    numeric = 1.5;
    } else if(overall<=100){
    numeric = 1;
    }
    if(numeric<=5){
    condition="FAILEd";
    } else if(numeric<=3){
    condition="PASSED";
    } else if(numeric<=2.5){
    condition="FAIR";
    } else if(numeric<=2){
    condition="GOOD";
    } else if(numeric<=1.5){
    condition="Very Good";
    } else if(numeric<=1){
    condition="Excellent!";
    }
    System.out.println("");
    System.out.println("PRELIM      MIDTERM      PREFINALS      FINALS");
    System.out.println(prelim+"        "+midterm+"         "+prefi+"           "+finals);
    System.out.println("Total grade is: "+overall+".");
    System.out.println(" "+condition);
    } else if(answer.equals(B)){
    if(overall<=74){
    numeric = 5;
    } else if(overall<=79){
    numeric = 3;
    } else if(overall<=84){
    numeric = 2.5;
    } else if(overall<=90){
    numeric = 2;
    } else if(overall<=95){
    numeric = 1.5;
    } else if(overall<=100){
    numeric = 1;
    }
    if(numeric<=5){
    condition="FAILEd";
    } else if(numeric<=3){
    condition="PASSED";
    } else if(numeric<=2.5){
    condition="FAIR";
    } else if(numeric<=2){
    condition="GOOD";
    } else if(numeric<=1.5){
    condition="Very Good";
    } else if(numeric<=1){
    condition="Excellent!";
    }
    System.out.println("");
    System.out.println("PRELIM      MIDTERM      PREFINALS      FINALS");
    System.out.println(prelim+"        "+midterm+"         "+prefi+"           "+finals);
    System.out.println("Total grade is: "+overall+".");
    System.out.println(numeric+" "+condition);
    } else{
    System.out.println("");
    System.out.println("Greetings " +lastname+ ", " +name+ " " +middlename+ "." + " your action had cost us to end this program please read the warning message carefully before using our program - Group2");
    return;
    }
    }
    }
    The error is with in this stuff, I really don't know what is wrong with it ):
    Java Code:
    if(overall<=74){
    numeric = 5;
    } else if(overall<=79){
    numeric = 3;
    } else if(overall<=84){
    numeric = 2.5;
    } else if(overall<=90){
    numeric = 2;
    } else if(overall<=95){
    numeric = 1.5;
    } else if(overall<=100){
    numeric = 1;
    }
    if(numeric<=5){
    condition="FAILEd";
    } else if(numeric<=3){
    condition="PASSED";
    } else if(numeric<=2.5){
    condition="FAIR";
    } else if(numeric<=2){
    condition="GOOD";
    } else if(numeric<=1.5){
    condition="Very Good";
    } else if(numeric<=1){
    condition="Excellent!";
    }
    Last edited by micolord; 10-05-2011 at 05:10 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Variable numeric might now have been initialized

    For future reference, it helps us and you to boil your code down to an SSCCE...that is a huge volume of code that contains no indenting (aka very unreadable). That being said, that error is quite explanatory - numeric might not have been initialized (your if/else if contains no else clause). So initialize it somehow, either at it declaration (int numeric = 0;) or with an else statement. FWIW you might want to double check your logic
    sunde887 likes this.

  3. #3
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Variable numeric might now have been initialized

    Quote Originally Posted by doWhile View Post
    your if/else if contains no else clause
    It does have.

  4. #4
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Variable numeric might now have been initialized

    And sorry for the title, it shouldn't be "Variable numeric might now have been initialized" when it should be "Variable numeric might not have been initialized" lol sorry xD

  5. #5
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Variable numeric might now have been initialized

    Can anyone here please help me :)

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Variable numeric might now have been initialized

    I suggest you re read doWhile's post, focusing on two things: Re-consider your logic. Don't drop 200+ unformatted lines of code and expect people look much into it.

  7. #7
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Variable numeric might now have been initialized

    I think I got it! But can I do this nested if? Can I do nest else if? please give me a proper example if so :D
    Java Code:
    if(ex<=1){
      S.O.P("test");
      if(ex2<=1){
        S.O.P("test");
      }
    } 
    else if(ex3<=5){
      S.O.P("wew");
      else if(){
        S.O.P("wew");
      }
    }
    Last edited by sunde887; 10-05-2011 at 05:51 PM.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Variable numeric might now have been initialized

    That may work, but can be done instead with || and &&. What you posted does have some problems though in the second if (first else if).

    Also, code tags: [code] YOUR CODE HERE [/code]

    and format your code please.

  9. #9
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Variable numeric might now have been initialized

    Quote Originally Posted by sunde887 View Post
    That may work, but can be done instead with || and &&. What you posted does have some problems though in the second if (first else if).

    Also, code tags: [code] YOUR CODE HERE [/code]

    and format your code please.
    CRAP. Didn't work. My nest else if code didn't work.

  10. #10
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Variable numeric might now have been initialized

    It will work if you fix the second nesting. else if should always have a corresponding if which comes before it. When nesting if's you think of the inner (nested loop) as different from the outer if.

    Java Code:
    if(condition){ //outer if
      if(condition){  //inner if 1
      }
    }
    else if(condition){ //outer if
      //anything in here is separate from the one above
    }

Similar Threads

  1. Variable not initialized?
    By seegee in forum New To Java
    Replies: 2
    Last Post: 07-15-2011, 03:00 PM
  2. Variable not initialized.
    By miss_peaches in forum New To Java
    Replies: 14
    Last Post: 04-27-2011, 10:28 AM
  3. variable name might not have been initialized
    By p0rnstar in forum New To Java
    Replies: 3
    Last Post: 01-26-2010, 04:27 PM
  4. Variable not initialized after while loop
    By ejs7597 in forum New To Java
    Replies: 6
    Last Post: 02-28-2009, 06:00 AM
  5. Not initialized variable
    By bbq in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 10:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •