For those who have tried Practical 3 Qns.7, this is my solution just to show you how to make use of switch statement on JAVA.
import javax.swing.JOptionPane;
public class GradeModSwitch {
public static void main(String[] args) {
char grade;
int score;
score= Integer.parseInt(JOptionPane.showInputDialog(null,"Please enter your score","Enter Score", JOptionPane.QUESTION_MESSAGE));
switch (score / 10){ // this can also accept expression
case 10:grade = 'A';
break;
case 9: grade = 'A';
break;
case 8: grade = 'A';
break;
case 7: grade = 'B';
break;
case 6: grade = 'C';
break;
case 5: grade = 'D';
break;
default: grade = 'F';
}
JOptionPane.showMessageDialog(null,"Your grade is " + grade,"Grading System",JOptionPane.INFORMATION_MESSAGE);
} // end main
} // end class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment