wood burning stoves*
The moose likes Beginning Java and the fly likes class ClockTime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "class ClockTime" Watch "class ClockTime" New topic
Author

class ClockTime

Amy Lee
Greenhorn

Joined: Nov 02, 2004
Posts: 25
I've been working on a class called ClockTime where methods are used to carry out various tasks on time. My code is as follows:



I'm having problems with method equals() and method before(). When I call method equals(), even if I plug values into each array that make them identical, it is returning the string that they are NOT equal. Same thing happens when I specify values that aren't equal.

When I call method before(), if I use values that make myTime occur before clock, it still returns false. Same thing happens vice versa.

I don't think I'm fully grasping the relationship between arrays and equality. Please help!

THANKS!
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
there should be a small correction made in the before method



it should be like

in your case it checks the hour first then the minutes and then the seconds. if hour is leeser and minute is greater or vice versa will affect the result. your code will work only if all the values are greater or all the values are less..

[ November 02, 2004: Message edited by: Karthikeyan Rajendraprasad ]
[ November 02, 2004: Message edited by: Karthikeyan Rajendraprasad ]

Karthikeyan<br />SCJP 1.4, SCWCD.
Amy Lee
Greenhorn

Joined: Nov 02, 2004
Posts: 25
So then I should get rid of the variable result and the return result statement outside of the for loop, right?

Thanks.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
no you cant remove it, if the time is equal you have to return using that variable only. you can either set it as true or false as per your requirement.
Amy Lee
Greenhorn

Joined: Nov 02, 2004
Posts: 25
Your method works - THANKS! - but I want to understand. I feel like this should be apparent but...

1. boolean result is declared outside the for loop and is initialized to true

2. there are three scenarios in the if statement

3. say the myTime occurs AFTER clock; the if statement will return false - myTime does not occur before clock

4. nowhere in the if statement does it assign the boolean false to result outside the for loop. how does the method know to return result as false if it is never assigned false and it was initialized to true to begin with?

Thanks for your patience.
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
oops i missed the && result condition in the for loop.

i think you can remove it and set the result as false so the method should look like
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class ClockTime
 
Similar Threads
How to use this() in overloaded subclass constructors ( and why) ?
where is the bug?
Constructor
How to calculate number of days between two Timestamp
How to calculate number of days between two Timestamp