temperature

Reply

Join Date: Jan 2009
Posts: 55
Reputation: javaman2 has a little shameless behaviour in the past 
Solved Threads: 0
javaman2 javaman2 is offline Offline
Junior Poster in Training

temperature

 
0
  #1
Feb 20th, 2009
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));
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,664
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: temperature

 
0
  #2
Feb 21st, 2009
Post your driver code and what errors you get
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 55
Reputation: javaman2 has a little shameless behaviour in the past 
Solved Threads: 0
javaman2 javaman2 is offline Offline
Junior Poster in Training

Re: temperature

 
0
  #3
Feb 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,664
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 224
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: temperature

 
0
  #4
Feb 22nd, 2009
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?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC