I am new to Java and can not figure out why I am getting this error for swithc case.
champagne 0 Newbie Poster
/****************************************************************
*
* program name: ConvertTemp05
*
* author: Glenda Scales
*
* date due: 09/30/2007
*
* remarks: ConvertTemp05 a java program that will
* convert Celsius to Fahrenhiet.
*
* ***********************************************************************/
import javax.swing.JOptionPane;
import java.text.*;
import java.text.DecimalFormat;
class ConvertTemp05
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null, "Temperature conversion program", "ConverTemp05",JOptionPane.PLAIN_MESSAGE);
String sCode = JOptionPane.showInputDialog(null,"Please enter the Temperature code a 'c' or 'C' to convert C--> F or a 'f'or 'F' to convert F--> C");
Char sCode = new character
(input = sCode.chartAt(0));
switch (sCode){
{
case 'c':
case 'C':
double f = (double)
( 9/5.0) * temp + 32;
break;
JOptionPane.showMessageDialog(null, (cel + " degrees in Celsius is " + df.format (f) + " degrees in Fahrenheit."));
case 'f':
case 'F':
double c = (double)
(5/9.0) * temp -32;
break;
default:
}
JOptionPane.showMessageDialog(null, fht + " degrees in Fahrenheit is " + df.format (cels) + " degrees in Celsius.");
String cel = JOptionPane.showInputDialog(null,
"Please enter the Temperature (as an int)");
String cel = JOptionPane.show.InputDialog(null, "Please enter the Temperature (as an int)");
DecimalFormat df = new
DecimalFormat("###,###,###,###.##");
JOptionPane.showMessageDialog(null, "you entered an invalid code of x you idiot " + "\n" + " enter a c, C, f, or F ","ConvertTemp05",JOptionPane.ERROR_MESSAGE);
}
}
// end main
// end class
iamthwee
1) Please post your code here.
2) Make sure you indent your code properly
3) Use [code]
[/code] tags
4) Post what error messages you get.
venkatev 0 Newbie Poster
Not sure what problem you are facing... but one obvious thing i spotted is that you are having a statement after the break; You might have got 'Unreachable code' error. If that's not your issue, could you elaborate on your problem? Also, could you please correct indentation?
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
You have two curly bracklets on start of switch statement and only one on closing
switch (sCode){
{
case 'c':
case 'C':
so delete one.
However once this done there is another 13 error messages which you need to sort. GL
champagne 0 Newbie Poster
I am new to Java and can not figure out why I am getting this error for swithc case.
I did correct the errors but I can not get the input message for Fahrenheit to show ConvertTemp05 in the heading box. and the 'c' to show. It only shows c. I have attached the correct code
Thanks a bunch
/****************************************************************
*
* program name: ConvertTemp05
*
* author: Glenda Scales
*
* date due: 09/30/2007
*
* remarks: ConvertTemp05 a java program that will
* convert Celsius to Fahrenhiet.
*
* ***********************************************************************/
import javax.swing.JOptionPane;
import java.text.*;
import java.text.DecimalFormat;
class ConvertTemp05
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null, "Temperature conversion program", "ConverTemp05",JOptionPane.PLAIN_MESSAGE);
String sCode = JOptionPane.showInputDialog(null,"Please enter the Temperature code a 'c' or 'C' to convert C--> F or a 'f'or 'F' to convert F--> C");
char sCode = new character
(input = sCode.chartAt(0));
switch (sCode){
case 'c':
case 'C':
double f = (double)
( 9/5.0) * temp + 32;
break;
JOptionPane.showMessageDialog(null, (cel + " degrees in Celsius is " + df.format (f) + " degrees in Fahrenheit." "ConvertTemp05");
case 'f':
case 'F':
double c = (double)
(5/9.0) * temp -32;
break;
default: Error;
}
JOptionPane.showMessageDialog(null, fht + " degrees in Fahrenheit is " + df.format (cels) + " degrees in Celsius." "ConvertTemp05");
String cel = JOptionPane.showInputDialog(null,
"Please enter the Temperature (as an int)");
String cel = JOptionPane.show.InputDialog(null, "Please enter the Temperature (as an int)");
DecimalFormat df = new
DecimalFormat("###,###,##");
JOptionPane.showMessageDialog(null, "you entered an invalid code of x you idiot " + "\n" + enter a 'c', 'C', 'f', or 'F'", "ConvertTemp05",JOptionPane.ERROR_MESSAGE);
}
}
// end main
// end class
orko 36 Junior Poster
The code you have given have following problems:
1. There is no java object type called "character". Might be you wanted "Character".
2. You have not defined what is "input" variable on line 28.
3. You have not defined "temp", "cel", "df" before you used them. You can not initiate them whenever you want. (Happened for "df")
4. This whole line has formatting error:
JOptionPane.showMessageDialog(null, (cel + " degrees in Celsius is " + df.format (f) + " degrees in Fahrenheit." "ConvertTemp05");
5. What is "fht"?????????????
Please fix these problems first, the program should work. (I am wondering how did you get any kind of output.. the code should not compile even)... Good luck.. :)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.