I am writing a class when testing I am encountering a problem. When I test my equals method, it is not doing my calculation and instead automatically returning true.
So basically my test class takes two temperatures with different degree scales and sees if they're equal. If an object has a char 'F' argument it's supposed to convert the temp to C to see if they're equal temps. But as stated my problem is when testing equals, no matter what values I put in it always reads the boolean as true. I can't figure out what I'm doing wrong. Any explanation would be helpful.
A snippet from my Temperature class:
public boolean equals(Object obj){
Temperature t = (Temperature) obj;
while (tempScale != t.tempScale){
temp = 5/9 *(t.temp-32);
}
return true;
}
}
and my test:
public class TemperatureDemo{
public static void main(String []args){
Temperature temp1 = new Temperature(0.0, 'C');
Temperature temp2 = new Temperature(35.0, 'F');
if (temp1.equals(temp2))
System.out.println("true");
else
System.out.println("false");
}
}
Aucun commentaire:
Enregistrer un commentaire