Variable might not have been initialized, don't understand why
<p>So I'm in an intro Java course, making a grade calculator with the added task of adjusting grades on this set of conditions:</p>

<p>If the student has done the bonus work:</p>

<ul>
<li>The Exam 1 grade is either:
<ul>
<li>80% of Exam 2’s grade if it is higher than the original Exam 1 grade, or</li>
<li>the original Exam 1 grade.</li>
</ul></li>
<li>The Exam 2 grade is either:
<ul>
<li>80% of Exam 3’s grade if it is higher than the original Exam 2 grade, or</li>
<li>the original Exam 2 grade.</li>
</ul></li>
</ul>

<p>The modification is always made for Exam 1 first.</p>

<p>I've tried this first with the exam 1 grade, attempting to assign <code>g1n</code> the value <code>g2 * 0.8</code> if <code>(g2 * 0.8) &gt; g1</code>, and giving it the value of <code>g1</code> otherwise. I'm having trouble seeing how <code>g1n</code> isn't being initialized since it seems to me like the conditions I've just listed are exhaustive.</p>

<p>Below is the relevant part of my code. What gives?</p>

<pre><code>// declare variables
int g1;
int g2;
int g3;
char grade;
double g1n;
double g2n;
double avg;
String bonus;

// get input
System.out.println("***************  Grade Computer *************");
System.out.println("Enter the student's first name: ");
String first = input.next();
System.out.println("Enter the student's middle initial: ");
String mid = input.next();
System.out.println("Enter the student's last name: ");
String last = input.next();
System.out.println("Enter EXAM 1 grade: ");
g1 = input.nextInt();
System.out.println("Enter EXAM 2 grade: ");
g2 = input.nextInt();
System.out.println("Enter EXAM 3 grade: ");
g3 = input.nextInt();
System.out.println("Was bonus work done? [yes/no]: ");
bonus = input.next();
System.out.println(g1 + " " + g2 + " " + g3 + " " + bonus);

// adjust exam scores if necesssary
if (bonus.equals("yes")) {
    if (((double)g2 * 0.8) &gt; g1) {
        g1n = ((double)g2 * 0.8);
    } else {
        g1n = (double)g1;
    }
}
</code></pre>

<p><strong>EDIT:</strong></p>

<p>I changed it to this and am still getting the same message...</p>

<pre><code>if (bonus.equals("yes")) {
    if (((double)g2 * 0.8) &gt; g1) {
        g1n = ((double)g2 * 0.8);
    }
    if (((double)g3 * 0.8) &gt; g2) {
        g2n = ((double)g3 * 0.8);
    }
} else {
    g1n = (double)g1;
    g2n = (double)g2;
}

// compute average
avg = (g1n + (double)g2 + (double)g3) / 3;
</code></pre>
