java help needed

admin

Administrator
Staff member
i need help finding out how to make this a program.. ive made some of it but am not sure about making the switch statments expression accurate help me if you can please....
i am supposed to write a java program that asks the user to type A, B C or Q. when the user types Q the program ends. when the user types A,B, or C, the program displays the message "good job!" and asks for another input. anything else typed, it prints an error message. then asks for another input of a, b, c, or d. the program should have while loop or the do while loop

import javax.swing.JOptionPane;
class exp
{
public static void main(String args[])
{
String response;
response = JOptionPane.showInputDialog(null, "Type a letter A,B,C or Q!" );

if (response == null)
{
JOptionPane.showMessageDialog(null, "*** Error *** You clicked on the cancel button");
JOptionPane.showInputDialog(null, "This time type A,B,C, or Q");
}
else
if (response.equals(""))
{
JOptionPane.showMessageDialog(null, "*** Error ***\n You have to make an entry in the Input Box");
JOptionPane.showInputDialog(null, "Try ggain,\n this time enter A,B,C, or Q!");
}

switch (response)
{
// after user typed a letter


case 1:
(response.equals ("A"));
JOptionPane.showMessageDialog(null, "GOOD JOB!");
break;

case 2:
(response.equals("B"));
JOptionPane.showMessageDialog(null, "GOOD JOB!");

break;
case 3:
(response.equals("C"));
JOptionPane.showMessageDialog(null, "GOOD JOB!");

break;
case 4:
(response.equals("Q"));
System.exit(0);

break;
default:
JOptionPane.showInputDialog(null, "Try again\n Type a letter A, B, C or Q");
System.exit(0);
}
}
}
 
Back
Top