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

  • Context: Java 
  • Thread starter Thread starter schapman22
  • Start date Start date
  • Tags Tags
    Java Method
Click For Summary
SUMMARY

The discussion focuses on creating a temperature class in Java that can compare Fahrenheit and Celsius objects for equality. Participants emphasize the need for constructors, accessor and mutator methods, and specifically an equals method that utilizes temperature conversion formulas. The key point is to implement a method that accepts two temperature parameters, one in Fahrenheit and one in Celsius, to determine if they are equivalent, returning true if they match based on the conversion formula.

PREREQUISITES
  • Java Object-Oriented Programming (OOP) concepts
  • Understanding of constructors and methods in Java
  • Knowledge of temperature conversion formulas
  • Experience with implementing equals methods in Java
NEXT STEPS
  • Research Java constructors and how to implement them effectively
  • Learn about Java method overloading and its applications
  • Study the implementation of the equals method in Java
  • Explore temperature conversion formulas and their applications in programming
USEFUL FOR

Java beginners, students learning object-oriented programming, and developers interested in implementing custom equality checks in Java classes.

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.
 

Similar threads

Replies
3
Views
4K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
8
Views
19K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
4
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K