Thursday, July 30, 2009

This still won't work! is the (char) System.in.read () incompatible in this program? Help please?

when i run this program in JCreator, this error appears (cannot resolve symbol method toUppercase (char)





import javax.swing.JOptionPane;


import java.io.*;


public class shipwin


{


public static void main (String args[]) throws IOException


{


char shipcode;


JOptionPane.showInputDialog ("Enter a ship code: ");





shipcode = (char) System.in.read();


shipcode = Character.toUppercase (shipcode);


switch (shipcode)


{


case 'B':JOptionPane.showMessageDialog (null,"Battleship");break;


case 'C':JOptionPane.showMessageDialog (null,"Cruiser);break;


case 'D':JOptionPane.showMessageDialog (null,"Destroyer);break;


case 'G':JOptionPane.showMessageDialog (null,"Gunboat);break;


default: JOptionPane.showMessageDialog (null,"Invalid code);


}


}


}

This still won't work! is the (char) System.in.read () incompatible in this program? Help please?
try


String answer = JOptionPane.showInputDialog ("Enter a ship code: ");





shipcode = answer.charAt(0);





instead of


System.in.read();
Reply:Alright, I noticed you wrote toUppercase. Same thing I do everytime I use that method. You have to use an upper case C. toUpperCase. Sorry if I wrote it wrong before.





all Java methods have the same naming convention. The first word starts with a lower case letter, but every other word in the function name starts with an upper case character.





so they always look like this.


myMethodName.





But I still don't know why it wasn't showing anything. Perhaps someone else can answer that. I would love to but since I'm not on my computer right now I can't run the program and find out and the answer isn't coming to me just from looking at the code for some reason.





I have been awake for 24 hours though. So sorry if I've made a mistake somewhere.


No comments:

Post a Comment