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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top