JAVA compilation errors

By mikev9359 ·
I'm taking an online course using JAVA Programming(4th Edition)by Joyce Farrell. I am at an excercise I just can't get past.
I'm trying to write a script that can convert Fahrenheit to Centigrade, but I can't seem to resolve my last few errors.

import javax.swing.JOptionPane;
public class TEST
public static void main(String[] args)
String FahrenheitString;
double Fahrenheit;
double Centigrade;

FahrenheitString = JOptionPane.showInputDialog(null,"Enter the Temperature in Fahrenheit ",

Temp = Double.parseDouble(FahrenheitString);
Centigrade = 5/9(FahrenheitString - 32);

JOptionPane.showMessageDialog (null, "The temperature in CENTIGRADES is + C=5/9(Fahrenheit-32");

Seems I have 3 errors due to "Centigrade = 5/9(FahrenheitString - 32);"
and 3 due to "JOptionPane.showMessageDialog (null, "The temperature in CENTIGRADES is
"+ C=5/9(Fahrenheit-32");
I just can't figure it out. Any guidance will be GREATLY appreciated.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by cmiller5400 In reply to JAVA compilation errors

Centigrade = 5/9(FahrenheitString - 32);
hint: Computers don't know to multiply automatically... parenthesis help with order of operations... and Where does temp go; can't just slam a string in a numeric field...

JOptionPane.showMessageDialog (null, "The temperature in CENTIGRADES is
"+ C=5/9(Fahrenheit-32")

Hint: Watch your quotes and parentheses... And why not use the variable that you set up so nicely...

Don't want to give you the answer, just point you in the right direction. Let me know if you need more help. :)

Collapse -

Regarding your errors

by leolore In reply to JAVA compilation errors


The errors in the two statements are the same errors. You don't learn as much if I just tell you the answer, so I'm going to hint at it. The formula
C = 5/9(Farenheight-32)
is correct math syntax, but is actually a shortcut. I suggest that you read the formula out loud, and figure out what you're saying that isn't written down.

I also somewhat expect that you will get an answer of 0 from that formula. It has to do with another difference between doing math on paper and doing it with a computer.

Let me know how it goes!

-- Leolore

Collapse -

Arithmetic in Java

by coderancher In reply to JAVA compilation errors

Just glancing at the table of contents for your textbook, it does not seem immediately obvious which chapter would explain how math works in Java. I'm guessing chapter 2 on using data within a program?

In Java (and most other programming languages) the 4 basic operators for addition, subtraction, multiplication, and division are +, -, *, and /, respectively. You must always explicitly include the multiply operator to multiply 2 terms. In algebra, you learned to write "x times y" as xy or (x)(y). In programming, you must write x*y or (x)*(y).

Related Discussions

Related Forums