This week's book giveaway is in the Testing forum. We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line! See this thread for details.
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!
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 ]
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?