435,039 Members | 1,831 Online
Need help? Post your question and get tips & solutions from a community of 435,039 IT Pros & Developers. It's quick & easy.

 P: n/a Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!! import javax.swing.*; import java.util.*; public class GradePoint { public static void main(String[] args) { String tempGrades; String[][] names = new String[10][6]; String outputGrades = new String(); float gpa; double A = 4; double a = 4; double B = 3; double b = 3; double C = 2; double c = 2; double D = 1; double d = 1; double F = 0; double f = 0; for(int x = 0; x < 3; x++) { names[x][0] = JOptionPane.showInputDialog(null, "Please Enter Student number " + (x + 1) + "s Name "); for(int y = 1; y < 6; y++) { do tempGrades = JOptionPane.showInputDialog(null, "Please Enter Grade for course number " + (y)); while (!tempGrades.equalsIgnoreCase("A") && !tempGrades.equalsIgnoreCase("B") && !tempGrades.equalsIgnoreCase("C") && !tempGrades.equalsIgnoreCase("D") && !tempGrades.equalsIgnoreCase("F")); names[x][y]=tempGrades; } } for(int x = 0; x < 3; x++) { outputGrades = "Students Name " + names[x][0] + "\n"; for(int y = 1; y < 6; y++) outputGrades += "Grade for course number " + y + ": " + names[x][y] + "\n"; JOptionPane.showMessageDialog(null, outputGrades); JOptionPane.showMessageDialog(null, names[x][y]); JOptionPane.showMessageDialog(null, "Grade Report Finished"); System.exit(0); } } Jul 17 '05 #1
4 Replies

 P: n/a "SCOTT DELIBAC" wrote in message news:... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!! You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap: HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0)); Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase()); Jul 17 '05 #2

 P: n/a "SCOTT DELIBAC" wrote in message news:... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!! You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap: HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0)); Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase()); Jul 17 '05 #3

 P: n/a Thank you I got it. -Scott -- Delibac "Karl von Laudermann" wrote in message news:e7**************************@posting.google.c om... "SCOTT DELIBAC" wrote in message news:... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!! You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap: HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0)); Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase()); Jul 17 '05 #4

 P: n/a Thank you I got it. -Scott -- Delibac "Karl von Laudermann" wrote in message news:e7**************************@posting.google.c om... "SCOTT DELIBAC" wrote in message news:... Can Anyone Help?? I have this program which is listed below. I want to take the grades that the students have assigned to them, and assign the letter grades a numeric value so that I can calculate their GPA. I just have no idea how I am supposed to do that?? Can anyone HELP!!! You can't access the variables A, a, B, b, etc. based on a string. Instead, store the grade values in a HashMap: HashMap grademap = new HashMap(); grademap.put("A", new Integer(4)); grademap.put("B", new Integer(3)); grademap.put("C", new Integer(2)); grademap.put("D", new Integer(1)); grademap.put("F", new Integer(0)); Then you can look up the numeric value based on the grade string: int value = grademap.get(names[x][y].toUpperCase()); Jul 17 '05 #5

### This discussion thread is closed

Replies have been disabled for this discussion.