I think I found what I`m looking for, but it`s not working how I want it to, it`s no doing anything the way I have it set up.
I put my formating function inside the convertTemp(), that`s probably not where it should be.
This is my code:
import java.text.DecimalFormat;
public class Temperature
{
private double temp;
private char tempScale;
public Temperature()
{
}
public Temperature(double t, char tempS)
{
setTemp (t);
setTempScale (tempS);
}
void displayTemp()
{
if (getTempScale() == 'F')
{
System.out.println("The current temperature is " + getTemp() + " " + getTempScale());
}
else
{
System.out.println("Which is equivalent to " + getTemp() + " " + getTempScale());
}
}
DecimalFormat oneDigit = new DecimalFormat("0.0");
double convertTemp()
{
if (tempScale == 'F')
{
temp = (temp - 32)* 5/9;
tempScale = 'C';
}
else
{
temp = temp * 9 / 5 + 32;
tempScale = 'F';
}
oneDigit.format(temp);
return 0;
}
int tempState()
{
if(getTemp() >= 212 && getTempScale() == 'F' || getTemp() >= 100 && getTempScale() == 'C')
{
System.out.print("Water at this temperature is a gas.\n");
}
else if(getTemp() >= 32 && getTempScale() == 'F' || getTemp() >= 0 && getTempScale() == 'C')
{
System.out.print("Water at this temperature is a liquid.\n");
}
else
{
System.out.print("Water at this temperature is solid.\n");
}
return 0;
}
void setTemp(double value)
{
temp = value;
}
void setTempScale(char type)
{
tempScale = type;
}
double getTemp()
{
return temp;
}
char getTempScale()
{
return tempScale;
}
}
and …