import javax.swing.JOptionPane;
import java.io.*;
public class shipwin
{
public static void main (String args [])throws IOException
{
char shipcode;
JOptionPane.showInputDialog ("Enter a shipcode: ");
shipcode = (char) System.in.read ();
switch (shipcode)
{
case 'B' : case 'b': JOptionPane.showMessage-
Dialog (null, "Battleship");break;
case 'C' : case 'c': JOptionPane.showMessage-
Dialog (null, "Cruiser");break;
case 'D' : case 'd': JOptionPane.showMessage-
Dialog (null, "Destroyer");break;
case 'G' : case 'g': JOptionPane.showMessage-
Dialog (null, "Gunboat");break;
default: JOptionPane.showMessage-
Dialog (null, "You entered an invalid code");
}
}
}
This program will not give a result!?
^ewwwww^ ugly
Reply:First, add extra lines between your switch statement.
Second, you need to check for a null first before you enter your switch,
use the statement
shipcode = shipcode.toUpperCase6() to get the upper case.
Reply:Take a look at this link
Reply:Your code needs to be separated. Find a way to make the answer always capital that way you can take out the cases for lower case, or make separate cases.
The way you have it setup is...ugly. I can't even tell if it's because the switch runs into two cases or because it runs into a case without code and a break.
otherwise it will work (assuming you got no compile errors)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment