Can't get this method to work

I'm having trouble with the method in my program "toCelsius" the toFahrenheit method is practically identical except for the reverse equation, and that works fine. When i run my program however, the output (in the toString method) always says 0 degrees celsius no matter what temperature it is, but if input as celsius it works fine.

example output:

Please enter the temperature outside.

85

Is this temperature in Celsius or Fahrenheit? Please enter "C" or "F".

c

Based on the temperature outside: 85.0 degrees Celsius (117.0 Fahrenheit) I suggest: swimming.

Please enter a temperature for another day or time.

85

Is this temperature in Celsius or Fahrenheit? Please enter "C" or "F".

f

Based on the temperature outside: 85.0 degrees Fahrenheit (0.0 Celsius) I suggest: swimming.

The two temperatures are not equal

class code:

publicclass TempActivity

{

String activity, scale, output;

double temp, tempC, tempF;

double convTemp;

public TempActivity()

{

temp = 0;

}

public TempActivity(int startTemp)

{

setTemp(startTemp);

}

publicdouble getTemp()

{

return temp;

}

publicvoid setTemp(double newTemp)

{

temp = newTemp;

}

public String getActivity()

{

if (getTemp()>=85)

activity ="swimming";

if (getTemp()>=70 && getTemp()<=84)

activity ="tennis";

if (getTemp()>=60 && getTemp()<=69)

activity ="hiking";

if (getTemp()<60)

activity ="board games";

return activity;

}

publicboolean equals(TempActivity activeA)

{

if (getTemp()==activeA.getTemp() && getScale().equals(activeA.getScale()))

returntrue;

else

returnfalse;

}

publicvoid toCelsius(double newC)

{

tempC = (newC-32)*(5/9);

convTemp = tempC;

}

publicvoid toFahrenheit(double newF)

{

tempF = (9/5)*(newF+32);

convTemp = tempF;

}

publicvoid setScale(String newScale)

{

scale = newScale;

}

public String getScale()

{

return scale;

}

public String toString()

{

if (getScale().equalsIgnoreCase("c"))

output ="Based on the temperature outside: " +temp +" degrees Celsius (" +convTemp +" Fahrenheit) I suggest: " +activity +".";

elseif (getScale().equalsIgnoreCase("f"))

output ="Based on the temperature outside: " +temp +" degrees Fahrenheit (" +convTemp +" Celsius) I suggest: " +activity +".";

return output;

}

}

client code:

import java.util.*;

publicclass TempActivityClient

{

publicstaticvoid main(String[] args)

{

double temp, tempA;

String activity, activityA, scale, scaleA;

TempActivity active =new TempActivity();

Scanner keyboard =new Scanner(System.in);

System.out.println("Please enter the temperature outside.");

temp = keyboard.nextInt();

System.out.println("Is this temperature in Celsius or Fahrenheit? Please enter \"C\" or \"F\".");

scale = keyboard.next();

if (scale.equalsIgnoreCase("c"))

{active.toFahrenheit(temp);

active.setScale("c");}

elseif (scale.equalsIgnoreCase("f"))

{active.toCelsius(temp);

active.setScale("f");}

else

System.out.println("Error: answer must be \"c\" or \"f\"");

active.setTemp(temp);

activity = active.getActivity();

System.out.println("");

System.out.println(active.toString());

TempActivity activeA =new TempActivity();

System.out.println("");

System.out.println("Please enter a temperature for another day or time.");

tempA = keyboard.nextInt();

System.out.println("Is this temperature in Celsius or Fahrenheit? Please enter \"C\" or \"F\".");

scaleA = keyboard.next();

if (scaleA.equalsIgnoreCase("c"))

{activeA.toFahrenheit(tempA);

activeA.setScale("c");}

elseif (scaleA.equalsIgnoreCase("f"))

{activeA.toCelsius(tempA);

activeA.setScale("f");}

else

System.out.println("Error: answer must be \"c\" or \"f\"");

activeA.setTemp(tempA);

activityA = activeA.getActivity();

System.out.println("");

System.out.println(activeA.toString());

System.out.println("");

if (active.equals(activeA))

System.out.println("The two temperatures are equal");

else

System.out.println("The two temperatures are not equal");

}

}

Message was edited by:

thecynicle1

[8548 byte] By [thecynicle1a] at [2007-11-27 4:14:08]
# 1
tempC = (newC-32)*(5/9);What does 5/9 equal?
CaptainMorgan08a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 2
Thats the equation to convert Fahrenheit to Celsius
thecynicle1a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 3
> tempC = (newC-32)*(5/9);> What does 5/9 equal?ah... sneaky nasty little mistake. I keep doing that one myself.
petes1234a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 4
> Thats the equation to convert Fahrenheit to CelsiusThere's more to his question (what does 5/9 equal?) than meets the eye. This is a common beginner's trap.
petes1234a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 5
Your toFarenheit() method is also wrong. It will always return the Celsius temperature + 32.
CaptainMorgan08a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 6
> Thats the equation to convert Fahrenheit to CelsiusWhat does this print out?System.out.println(5 / 9);
CaptainMorgan08a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 7
Should i change it to 0.55?
thecynicle1a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 8
I changed it to 0.55 and 1.8 and it works, or is there a better way to do it more accurately? I don't really understand why it can't do the math.Message was edited by: thecynicle1
thecynicle1a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 9
> Should i change it to 0.55?That would work, but(5.0 / 9.0)Is it bit more accurate.
CaptainMorgan08a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...
# 10
> I don't really understand why it can't do the math.An int divided by an int is an int. 0.555 can't be stored in an int, so it truncates it. It doesn't round either.
CaptainMorgan08a at 2007-7-12 9:20:28 > top of Java-index,Java Essentials,Java Programming...