M
mandy
why am I getting this error "varible temp1 might not have been
initialized" and "varible temp2 might not have been initialized"
Here is the method tht returns a boolean comparison result:
// call in driver as t1.isLess(t2)
public boolean isLess(HW_413_7_Temperature Temperature2)
{
float temp1, temp2;
char scale1 = this.charScale;
char scale2 = Temperature2.charScale;
if( (scale1 == 'c' || scale1 == 'C') && (scale2 == 'f' || scale2 ==
'F') )
{
temp1 = this.temperature;
temp2 = Float.parseFloat(Temperature2.getCelsiusTemperature()
);
// need to parse back to float in order to compare
}
if( (scale1 == 'f' || scale1 == 'F') && (scale2 == 'c' || scale2 ==
'C') )
{
temp1 = Float.parseFloat(this.getCelsiusTemperature() );
// need to parse back to float in order to compare
temp2 = Temperature2.temperature;
}
if ( ( (scale1 == 'f' || scale1 == 'F') && (scale2 == 'f' || scale2
== 'F') ) || ( (scale1 == 'c' || scale1 == 'C') && (scale2 == 'c' ||
scale2 == 'C') ) )
{
temp1 = this.temperature;
temp2 = Temperature2.temperature;
}
return (temp1<=temp2);
}
initialized" and "varible temp2 might not have been initialized"
Here is the method tht returns a boolean comparison result:
// call in driver as t1.isLess(t2)
public boolean isLess(HW_413_7_Temperature Temperature2)
{
float temp1, temp2;
char scale1 = this.charScale;
char scale2 = Temperature2.charScale;
if( (scale1 == 'c' || scale1 == 'C') && (scale2 == 'f' || scale2 ==
'F') )
{
temp1 = this.temperature;
temp2 = Float.parseFloat(Temperature2.getCelsiusTemperature()
);
// need to parse back to float in order to compare
}
if( (scale1 == 'f' || scale1 == 'F') && (scale2 == 'c' || scale2 ==
'C') )
{
temp1 = Float.parseFloat(this.getCelsiusTemperature() );
// need to parse back to float in order to compare
temp2 = Temperature2.temperature;
}
if ( ( (scale1 == 'f' || scale1 == 'F') && (scale2 == 'f' || scale2
== 'F') ) || ( (scale1 == 'c' || scale1 == 'C') && (scale2 == 'c' ||
scale2 == 'C') ) )
{
temp1 = this.temperature;
temp2 = Temperature2.temperature;
}
return (temp1<=temp2);
}