intence
March 22nd, 2007, 09:20 PM
For my assignment I am to collect letter grades for the listed courses, then have the course, course grade, and an average GPA displayed at the end. I used one of my old assignments as template. An A = 4, B = 3, C = 2, D = 1, and F = 0.
Im stuck on trying to have a string collected instead of an integer for the letter grade. When I change it i get an error and not sure what to do. Also having trouble displaying average GPA from collected courses. Any help would be greatly appreciated and I wouldn't mind paying you for your time.
Thanks
import javax.swing.JOptionPane;
public class Lab45
{
public static void main(String[] args)
{
String outputString = "";
double totaCourses = 0;
boolean moreCourses = true;
do {
// get course
String course = getCourse();
// get grade
int grade = getGrade(course);
// add to output
outputString += formatInfoFor(course, grade);
// update running totals
totaCourses += course(grade);
// ask if more
moreCourses = askIfMoreCourses();
} while (moreCourses);
// print GPA
printGrade(outputString, totaCourses);
}
public static String getCourse()
{
return JOptionPane.showInputDialog(null,
"Enter course taken (IT101, IT103, IT108, IT212, IT214, IT223, IT341)");
}
public static int getGrade(String courseTitle)
{
int grade = Integer.parseInt(
JOptionPane.showInputDialog(null,
"Enter grade for: " + courseTitle + "."));
return grade;
}
public static String formatInfoFor(String cd,
int number)
{
return cd + " " + number + "\n";
}
public static double course(int grade)
{
double amount = (grade);
return amount;
}
public static boolean askIfMoreCourses()
{
int response = Integer.parseInt(
JOptionPane.showInputDialog(null,
"Do you have another course?\n\n1 - yes\n2 - no"));
return (response == 1);
}
public static void printGrade(String outputString,
double courses)
{
outputString += "\n\nGPA: "
+ (courses);
JOptionPane.showMessageDialog(null, outputString);
}
}
Im stuck on trying to have a string collected instead of an integer for the letter grade. When I change it i get an error and not sure what to do. Also having trouble displaying average GPA from collected courses. Any help would be greatly appreciated and I wouldn't mind paying you for your time.
Thanks
import javax.swing.JOptionPane;
public class Lab45
{
public static void main(String[] args)
{
String outputString = "";
double totaCourses = 0;
boolean moreCourses = true;
do {
// get course
String course = getCourse();
// get grade
int grade = getGrade(course);
// add to output
outputString += formatInfoFor(course, grade);
// update running totals
totaCourses += course(grade);
// ask if more
moreCourses = askIfMoreCourses();
} while (moreCourses);
// print GPA
printGrade(outputString, totaCourses);
}
public static String getCourse()
{
return JOptionPane.showInputDialog(null,
"Enter course taken (IT101, IT103, IT108, IT212, IT214, IT223, IT341)");
}
public static int getGrade(String courseTitle)
{
int grade = Integer.parseInt(
JOptionPane.showInputDialog(null,
"Enter grade for: " + courseTitle + "."));
return grade;
}
public static String formatInfoFor(String cd,
int number)
{
return cd + " " + number + "\n";
}
public static double course(int grade)
{
double amount = (grade);
return amount;
}
public static boolean askIfMoreCourses()
{
int response = Integer.parseInt(
JOptionPane.showInputDialog(null,
"Do you have another course?\n\n1 - yes\n2 - no"));
return (response == 1);
}
public static void printGrade(String outputString,
double courses)
{
outputString += "\n\nGPA: "
+ (courses);
JOptionPane.showMessageDialog(null, outputString);
}
}