I'm working on a Grade Point Average Calculator.
The user just have to Select the number of courses offered, then select the grade obtain in the different courses by choosing the appropriate grade from the Choice Box.
The problem with my application is that, if the user mistakenly selects "A" instead of "B", then he corrects his mistake by selecting "B", the program sums up all the selections, including the wrong selection. So the calculation ends up being wrong.
Another proble with my application is that, u can't select an item twice. i.e if a user, selects "A" in the first Choice box, he can't select "A" again in the same Choice box, in case he wants to do another calculation.
This is the source code for the gradeChoice class.....
import java.awt.*;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.*;
/*
*
*@author Anokam Kingsley
*/
GradeChoice(){
super();
final String[] Grades = {"Grades","A","A-","B+","B","B-","C+","C","C-","D","F"};
for(String grades : Grades){
add(grades);
}
addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
String gradeString = getSelectedItem();
switch(gradeString){
case "A" :
gradeMark = 4.00;
break;
case "A-":
gradeMark = 3.67;
break;
case "B+":
gradeMark = 3.34;
break;
case "B":
gradeMark = 3.00;
break;
case "B-":
gradeMark = 2.67;
break;
case "C+":
gradeMark = 2.34;
break;
case "C":
gradeMark = 2.00;
break;
case "C-":
gradeMark = 1.67;
break;
case "D":
gradeMark = 1.00;
break;
case "F":
gradeMark = 0.00;
break;
default:
System.out.println("Error!!");
}
Scores += gradeMark;
}}); //End of addItemListener
}//End of GradeChoice constructor
static double gradeMark,Scores;;
}// End of class.
i'd be very grateful if someone helps me