📄 temperature.java
字号:
public class temperature
{
public double tempValue;
public char scale;//C(Celsius) or F(Fahrenheit).
public temperature()
{
tempValue=0.0;
scale='C';
}
public temperature(double newTempValue)
{
tempValue=newTempValue;
scale='C';
}
public temperature(char newscale)
{
tempValue=0.0;
if(newscale!='C'&&newscale!='F')
{
char otherscale;
do{
System.out.println("Error:no such a scale.Input a correct scale:");
otherscale=SavitchIn.readChar();
}while(otherscale!='C'&&otherscale!='F');
scale=otherscale;
}
else
scale=newscale;
}
public temperature(double newTempValue,char newscale)
{
tempValue=newTempValue;
if(newscale!='C'&&newscale!='F')
{
char otherscale;
do{
System.out.println("Error:no such a scale.Input a correct scale:");
otherscale=SavitchIn.readChar();
}while(otherscale!='C'&&otherscale!='F');
scale=otherscale;
}
else
scale=newscale;
}
public double getTempC()
{
if(scale=='C')
{
return tempValue;
}
else
{
return 5*(tempValue-32)/9;
}
}
public double getTempF()
{
if(scale=='F')
{
return tempValue;
}
else
{
return ((9*(tempValue)/5)+32);
}
}
public void reset(double newTempValue)
{
tempValue=newTempValue;
}
public void reset(char newscale)
{
if(newscale!='C'&&newscale!='F'){
System.out.println("Error:no such a scale.");
}
else
scale=newscale;
}
public void reset(double newTempValue,char newscale)
{
tempValue=newTempValue;
if(scale!='C'&&scale!='F')
{
System.out.println("Error:no such a scale.");
}
else
scale=newscale;
}
public boolean wheatherEqual(temperature theOtherTemp)
{
if(this.scale==theOtherTemp.scale)
{
if(tempValue==theOtherTemp.tempValue)
return true;
else
return false;
}
else
{
if(theOtherTemp.scale=='F')//convert to C;
{
double otherTemp=5*(theOtherTemp.tempValue-32)/9;
if(this.tempValue==otherTemp)
return true;
else
return false;
}
else
{
double otherTemp=(9*(tempValue)/5)+32;//convert to F;
if(this.tempValue==otherTemp)
return true;
else
return false;
}
}
}
public boolean wheatherGreater(temperature theOtherTemp)
{
if(this.scale==theOtherTemp.scale)
{
if(this.tempValue>theOtherTemp.tempValue)
return true;
else
return false;
}
else
{
if(theOtherTemp.scale=='F')//convert to C;
{
double otherTemp=5*(theOtherTemp.tempValue-32)/9;
if(this.tempValue>otherTemp)
return true;
else
return false;
}
else
{
double otherTemp=(9*(tempValue)/5)+32;//convert to F;
if(this.tempValue>otherTemp)
return true;
else
return false;
}
}
}
public boolean wheatherLess(temperature theOtherTemp)
{
if(this.scale==theOtherTemp.scale)
{
if(this.tempValue<theOtherTemp.tempValue)
return true;
else
return false;
}
else
{
if(theOtherTemp.scale=='F')//convert to C;
{
double otherTempValue=5*(theOtherTemp.tempValue-32)/9;
if(this.tempValue<otherTempValue)
return true;
else
return false;
}
else
{
double otherTempValue=(9*(tempValue)/5)+32;//convert to F;
if(this.tempValue<otherTempValue)
return true;
else
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -