// This is the error message I'm getting..C:\Program Files\Java\jdk1.6.0_25\bin>javac c:\java\Grade1.java
// c:\java\Grade1.java:49: variable grades might not have been initialized
// switch(grades)
// ^
import java.util.Scanner;
import java.text.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
public class Grade1
{
public static void main (String[] args)
{
String str, lgrade, studentName, courseName;
int studentNo, totalsum, noCourse, c;
char grades;
double gp = 0.0;
double totalgp = 0.0;
double gpa = 0.0;
double n = 0.0;
studentName = JOptionPane.showInputDialog(null,"Enter Student Name");
str = JOptionPane.showInputDialog(null,"Enter Student Number:");
studentNo = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter Number of Courses:");
noCourse = Integer.parseInt(str);
//try statement
try
{
//set up buffered output filestream
FileWriter fw = new FileWriter("grades.txt");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println("ABC College Report For");
pw.println(studentName);
pw.println(studentNo);
pw.println("\n");
pw.println("\nCourse" + " " + "Letter Grade" + " " + "Gradepoints");
for(c = 0; c < noCourse; ++c)
{
courseName = JOptionPane.showInputDialog(null, "Enter Course Name & Section:");
lgrade = JOptionPane.showInputDialog(null, "Enter Grade:");
switch(grades)
{
case 'A': gp=4;
break;
case 'B': gp=3;
break;
case 'C': gp=2;
break;
case 'D': gp=1;
break;
default: gp=0;
}
totalgp+=gp;
pw.println(courseName + " " + lgrade + " " + gp);
}
gpa = (totalgp / n);
pw.println("GPA: " + gpa);
pw.close(); //close file
}
//catch statement
catch(IOException e)
{
System.out.println("Error: " + e.getMessage());
}
// finally statement
finally
{
System.exit(0);
}
}
}
dwlniles 0 Newbie Poster
zeroliken 79 Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.