English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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");
}
}
}

2007-09-27 20:11:07 · 4 answers · asked by sheryl lyn b 2 in Computers & Internet Programming & Design

4 answers

Take a look at this link

2007-09-27 20:23:20 · answer #1 · answered by AnalProgrammer 7 · 1 0

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)

2007-09-28 03:25:10 · answer #2 · answered by Anonymous · 0 0

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.

2007-09-28 15:48:20 · answer #3 · answered by ckcool192000 3 · 0 0

^ewwwww^ ugly

2007-09-28 03:18:18 · answer #4 · answered by icygurl423152000 2 · 0 1

fedest.com, questions and answers