| | |
temperature
![]() |
•
•
Join Date: Jan 2009
Posts: 55
Reputation:
Solved Threads: 0
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));
}
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));
}
Post your driver code and what errors you get
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Jan 2009
Posts: 55
Reputation:
Solved Threads: 0
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
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
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?
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?
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- AMD64 3400+ concerned about temperature! (Motherboards, CPUs and RAM)
- critical cpu temperature in ibook (Apple Hardware)
- CPU Temperature (Motherboards, CPUs and RAM)
- CPU temperature control/overheating (Motherboards, CPUs and RAM)
- MAJOR Temperature Sensing problem! (Cases, Fans and Power Supplies)
- Temperature Issue? (Cases, Fans and Power Supplies)
Other Threads in the Java Forum
- Previous Thread: Birthday Problem Help!!
- Next Thread: downloading to a certain directory
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






