Hello.

Taking a Java course, but I have been stuck on this code for over a week, and its already due. My problem is, is that I have declared global variables, but the local variables are never read. The program is designed to take course hours and grade and spit out the GPA.

Input should be:


LAB07 BASIC VERSION


Enter course 1 Grade ===>> A
enter course 1 Hours ===>> 4
Enter course 2 Grade ===>> A
enter course 2 Hours ===>> 3
Enter course 3 Grade ===>> A
enter course 3 Hours ===>> 2
Enter course 4 Grade ===>> A
enter course 4 Hours ===>> 1

Course1 Grade: A Course1 Credit Hours: 4
Course2 Grade: A Course2 Credit Hours: 3
Course3 Grade: A Course3 Credit Hours: 2
Course4 Grade: A Course4 Credit Hours: 1

Current GPA: 4.0

Everything current works, except for the "Current GPA: 0".. It needs to have "4.0" and have all variables read.



Current code is below:




//CODE BEGINS

import java.util.*;

public class Lab07
{

static String lGrade1, lGrade2, lGrade3, lGrade4;
static int cHours1,cHours2,cHours3,cHours4;
static int cVal1, cVal2, cVal3, cVal4;
static int gradeValue, courseValue;
static int gVal1, gVal2, gVal3, gVal4;
static int value;
static int gpa;
static String dummy;


public static void main (String args[])
{
System.out.println("\nLAB07 BASIC VERSION\n\n");
enterData();
computeGPA();
displayData();
gradeValue();
courseValue();
getGPA();
}




public static void enterData()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter course 1 Grade ===>> ");
lGrade1 = in.nextLine();
System.out.print("enter course 1 Hours ===>> ");
cHours1 = in.nextInt(); dummy = in.nextLine();
System.out.print("Enter course 2 Grade ===>> ");
lGrade2 = in.nextLine();
System.out.print("enter course 2 Hours ===>> ");
cHours2 = in.nextInt(); dummy = in.nextLine();
System.out.print("Enter course 3 Grade ===>> ");
lGrade3 = in.nextLine();
System.out.print("enter course 3 Hours ===>> ");
cHours3 = in.nextInt(); dummy = in.nextLine();
System.out.print("Enter course 4 Grade ===>> ");
lGrade4 = in.nextLine();
System.out.print("enter course 4 Hours ===>> ");
cHours4 = in.nextInt(); dummy = in.nextLine();
}
public static void computeGPA()
{

int value = 0;

char lg1 = lGrade1.charAt(0);
switch(lg1)
{
case 'A': value = 4; break;
case 'B': value = 3; break;
case 'C': value = 2; break;
case 'D': value = 1; break;
case 'F': value = 0; break;
}
int gVal1 = value;

char lg2 = lGrade2.charAt(0);
switch(lg2)
{
case 'A': value = 4; break;
case 'B': value = 3; break;
case 'C': value = 2; break;
case 'D': value = 1; break;
case 'F': value = 0; break;
}
int gVal2 = value;

char lg3 = lGrade3.charAt(0);
switch(lg3)
{
case 'A': value = 4; break;
case 'B': value = 3; break;
case 'C': value = 2; break;
case 'D': value = 1; break;
case 'F': value = 0; break;
}

int gVal3 = value;

char lg4 = lGrade4.charAt(0);
switch(lg4)
{

case 'A': value = 4; break;
case 'B': value = 3; break;
case 'C': value = 2; break;
case 'D': value = 1; break;
case 'F': value = 0; break;
}
}

public static void gradeValue()
{
int gVal4 = value;
}

public static void courseValue()
{
int cVal1 = gVal1 * cHours1;
int cVal2 = gVal2 * cHours2;
int cVal3 = gVal3 * cHours3;
int cVal4 = gVal4 * cHours4;

double totalValue = cVal1 + cVal2 + cVal3 + cVal4;
double totalHours = cHours1 + cHours2 + cHours3 + cHours4;
double gpa = totalValue / totalHours;
}

public static void displayData()
{
System.out.println();
System.out.println("Course1 Grade: " + lGrade1 + " Course1 Credit Hours: " + cHours1);
System.out.println("Course2 Grade: " + lGrade2 + " Course2 Credit Hours: " + cHours2);
System.out.println("Course3 Grade: " + lGrade3 + " Course3 Credit Hours: " + cHours3);
System.out.println("Course4 Grade: " + lGrade4 + " Course4 Credit Hours: " + cHours4);
System.out.println();
}

public static void getGPA()
{
System.out.println("Current GPA: " + gpa);
}
}