Java How to Check Equality Between Fahrenheit and Celsius Objects in Java?

  • Thread starter Thread starter schapman22
  • Start date Start date
  • Tags Tags
    Java Method
AI Thread Summary
Creating a temperature class in object-oriented programming involves implementing constructors, accessor methods, and mutator methods, particularly for Celsius to Fahrenheit conversions. A key challenge is developing an equals method to determine if a Fahrenheit object and a Celsius object represent the same temperature. To achieve this, temperature data should be stored effectively within the class. A method is needed that accepts two parameters—one for Fahrenheit and one for Celsius—and applies the conversion formula to check for equivalence, returning true if the temperatures match. This exercise emphasizes the importance of understanding the underlying details of object-oriented design and data handling.
schapman22
Messages
74
Reaction score
0
I'm having to create a temperature class for one of my assignments, were just getting into oop. Basically we just create a few constructors, accessor and mutator methods. The mutator methods are where celsius-farenheit conversions are. And we need to make an equals method which I know how to do but I don't know how you check to see if a fahrenheit object and a celsius are equal. Like if one object is set to 32F and another is 0C then it should return true.
 
Technology news on Phys.org
Have a think about how you would store the temperature data in your class, there's a few ways you could try. When you have the data stored appropriately you need a method that takes two parameters (two temperatures, one in fahrenheit and one in celsius) and uses the conversion formula to check if the values are equivalent, and if they are, return true.

It's a good exercise and it's worth figuring out the small details for yourself.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Back
Top