• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class ClockTime

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Amy Lee
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic