i need help with converting celsius to fahrenheit and vice versa in my program. for example, if someone would input 0C for the first temperature and 32F for the second temperature, i need to convert one of these temperatures so that my equals method can recognize that they are equal and output that both temperatures are equal.

I've attempted to do this with the calculateCelsius() method but it doesnt work if i try to run it in my driver program

Thank you for any help

public double getValueF()
{
    if(scale=='F')
        return value;
    else
        return(9*(value/5)+32);
}

public double getValueC()
{
    if(scale=='C')
        return value;
    else
        return(5*(value-32)/9);
}

public char getScale()
{
    return scale;
}

public void setValue(double t)
{
    value = t;
}

public void setScale(int s)
{
    if(s==1)
        scale = 'C';
    else
        scale = 'F';
}

public double caluculateCelsius()
{
    if(scale=='F')
        value = (5*(value-32)/9);
        return value;
}

public boolean equals(Temperature temp2)
{
    return ((this.value==temp2.value)&&(this.scale==temp2.scale));
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

import java.util.Scanner;

public class tempAllow
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        Temperature hot = new Temperature();
        System.out.println("Enter a temperature.");
        hot.setValue(keyboard.nextDouble());
        System.out.println("Enter 1 if scale is Celsius or 2 if scale if Fahrenheit.");
        hot.setScale(keyboard.nextInt());
        System.out.println(hot.calculateCelsius());
        System.out.println("Temperature in Fahrenheit is: " + hot);
        System.out.println(hot);


        Temperature cold = new Temperature();
        System.out.println("Enter a temperature and the scale.");
        cold.setValue(keyboard.nextDouble());
        System.out.println("Enter 1 is scale is Celsius or 2 if scale is Fahrenheit.");
        cold.setScale(keyboard.nextInt());
        System.out.println(cold.calculateCelsius());
        System.out.println("Temperature in Fahrenheit is: " + cold);
        System.out.println(cold);

        if(hot.equals(cold))
            System.out.println("The temperatures are the same.");
        else if(hot.compareBoth(cold))
            System.out.println("The temperatures are different.");
        else 
            System.out.println("The temperatures are uncomparable.");

The compiler says that it "cannot find symbol method calculateCelsius()"
Thank you for your help

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Use code tags, say at which line you get the error, and
Obviously from the compiler message:
cannot find symbol method calculateCelsius()
You have not declared such method.

The compiler tells you exactly what is your problem and at which line. Is it so difficult to read it?

This article has been dead for over six months. Start a new discussion instead.