Question: For this problem I'm suppose to switch the ifelse chain to a switch statement and I did. My problem is that I am getting two

For this problem I'm suppose to switch the ifelse chain to a switch statement and I did. My problem is that I am getting two errors when I run the program from switch(testScore / 10): because of the colon and the other for the bracket { underneath that switch statement. Could you correct this and tell me what I did wrong.

import javax.swing.JOptionPane;

class Main {

public static void main(String[] args) {

int testScore;

String input;

input = JOptionPane.showInputDialog("Enter your numeric "+ "test score and I wil ltell you the grade:");

testScore = Integer.parseInt(input);

switch(testScore / 10):

{

case 10: JOptionPane.showMessageDialog(null, "Your grade is an A.");

break;

case 9: JOptionPane.showMessageDialog(null, "Your grade is a B.");

break;

case 8: JOptionPane.showMessageDialog(null, "Your grade is a C.");

break;

case 7: JOptionPane.showMessageDialog(null, "Your grade is a D.");

break;

case 6: JOptionPane.showMessageDialog(null, "Your grade is a F.");

break;

defualt: JOptionPane.showMessageDialog(null, "Your grade is a F.");

break;

}

System.exit(0);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!