Java creating equals method

  • Java
  • Thread starter schapman22
  • Start date
  • #1
74
0

Main Question or Discussion Point

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.
 

Answers and Replies

  • #2
191
3
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.
 

Related Threads on Java creating equals method

  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
6K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
3
Views
4K
Replies
3
Views
11K
Replies
6
Views
12K
Replies
3
Views
2K
Replies
9
Views
4K
Top