Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class SwitchErrorsGui { public static void main(String[] args) { String i

ID: 3554931 • Letter: P

Question

public class SwitchErrorsGui

{

public static void main(String[] args)

{

String input:

JOptionPane.showMessageDialog(null,"Key :1=blue, 2=red, 3=green");

input = JOptionPane.showInputDialog("Enter a number and I'll return the corresponding color");

int number= Integer.parseInt(input);

switch(number)

{

case 1:

JOptionPane.showMessageDialog(null,"You choose red! ");

break;

case 2:

JOptionPane.showMessageDialog(null,"You choose blue! ");

break;

case 3:

JOptionPane.showMessageDialog(null,"You choose green! ");

break;

default:

JOptionPane.showMessageDialog(null,"Color not available! ");

break;

}

System.exit(0);

}

}

Explanation / Answer

import javax.swing.JOptionPane;


public class SwitchErrorsGui {

public static void main(String[] args) {

String input;

JOptionPane.showMessageDialog(null, "Key :1=blue, 2=red, 3=green");
input = JOptionPane.showInputDialog("Enter a number and I'll return the corresponding color");

int number = Integer.parseInt(input);
switch (number) {
case 1:

JOptionPane.showMessageDialog(null, "You choose red! ");

break;

case 2:

JOptionPane.showMessageDialog(null, "You choose blue! ");

break;

case 3:

JOptionPane.showMessageDialog(null, "You choose green! ");

break;

default:

JOptionPane.showMessageDialog(null, "Color not available! ");

break;

}

System.exit(0);
}
}