您好,我对学校和IM有困难的大量试图找出为什么我的程序总是告诉我的IM在我所有的方法缺少return语句的一个项目工作,缺少返回值
这里是我的代码:
public class Temperature {
private int temperature;
//constructors
public int Test(int temperature)
{
temperature = temperature;
return temperature;
}
public int TempClass()
{
temperature = 0;
return 0;
}
// get and set methods
public int getTemp()
{
return temperature;
}
public void setTemp(int temp)
{
temperature = temp;
}
//methods to determine if the substances
// will freeze or boil
public static boolean isEthylFreezing(int temp)
{
int EthylF = -173;
if (EthylF <= temp)
{System.out.print("Ethyl will freeze at that temperature");}
else
return false;
}
public boolean isEthylBoiling(int temp)
{
int EthylB = 172;
if (EthylB >= temp)
System.out.print("Ethyl will boil at that temperature");
else
return false;
}
public boolean isOxygenFreezing(int temp)
{
int OxyF = -362;
if (OxyF <= temp)
System.out.print("Oxygen will freeze at that temperature");
else
return false;
}
public boolean isOxygenBoiling(int temp)
{
int OxyB = -306;
if (OxyB >= temp)
System.out.print("Oxygen will boil at that temperature");
else
return false;
}
public boolean isWaterFreezing(int temp)
{
int H2OF = 32;
if (H2OF <= temp)
System.out.print("Water will freeze at that temperature");
else
return false;
}
public boolean isWaterBoiling(int temp)
{
int H2OB = 212;
if (H2OB >= temp)
System.out.print("Water will boil at that temperature");
else
return false;
}
}
'public int Test(int temperature) { temperature = temperature; 返回温度; }'a)不是构造函数,b)不会将参数赋值给对象的字段。 –
你为什么认为你得到这个错误? –
除了您的代码的其他问题,我相信您的“<=' and '> =”操作都是向后的。 –