• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call an increment method()  RSS feed

 
Stephen Corrad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm stuck on this method since this morning and I hope that someone can help me with it.

I have the following:

public class HistoricalMoment{

private String eventName;
private ClockDisplay timeOfEvent;
public static final int MIDNIGHT_HOUR = 00;
public static final int MINUTE_ZERO = 00;
}

How can I create a method called public void addMinuteToTimeOfEvent() which calls the timeOfEvent's increment() method to add one minute to the timeOfEvent?

Thanks in advance for your help!
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well what have you got so far?
Or what is your best guess as to what it should be?
 
Stephen Corrad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Stefan. I've created 3 constructors so far but when it comes to create the addMinuteToTimeOfEvent method I got stuck as the compiler cannot find the increment method() symbol. Any thoughts?

Thanks

public class HistoricalMoment{

private String eventName;
private ClockDisplay timeOfEvent;
public static final int MIDNIGHT_HOUR = 00;
public static final int MINUTE_ZERO = 00;
public static final String EQUINOX = "March 2013 Equinox!";
public static final String TITANIC = "Titanic hit an iceberg!";

/**
* Default Constructor
*/
public HistoricalMoment(){
eventName = "untitled event";
timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
}

/**
* @param nameOfTheEvent the name of the event; "untitled event" if the name of the event is null or ""
*/
public HistoricalMoment(String nameOfTheEvent){
if ((nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
eventName = "untitled event";
timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
}
else {
eventName = nameOfTheEvent;
timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
}
}

/**
* @param nameOfTheEvent the name of the event;
* @param ClockDisplay, the time of the event
*/
public HistoricalMoment(String nameOfTheEvent, ClockDisplay theTime){
if ((nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
eventName = "untitled event";
timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
}
else {
eventName = nameOfTheEvent;
timeOfEvent = theTime;
}
}

public void addMinuteToTimeOfEvent(){
timeOfEvent.increment();

}
}
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>How can I create a method called public void addMinuteToTimeOfEvent() which calls the timeOfEvent's increment() method to add one minute to the timeOfEvent?

So you have the code to do exactly what you said.



You say you get the error message
> compiler cannot find the increment method() symbol.

So what does the ClockDisplay class look like?
Is it one you wrote?
What methods does it have?
 
Stephen Corrad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen.

One small thing that might help in posting code is to UseCodeTags <-- (Click to find out how)
It means that code is nicely formatted for reading here - which helps a heck of a lot.

Also, rather than posting hundreds of lines of code, most of which are probably irrelevant, see if you can narrow it down to a main area of interest.
The easier you make it on the person reading the forum, the more likely they are to answer you!

So, I don't see any method called "increment" in ClockDisplay - though it does appear to use an increment method on its internal NumberDisplay objects.
Is there another method of clockDisplay that might suit your purpose?

 
Stephen Corrad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that Stefan, I will be more accurate from now on. Unfortunately I don't have any method called increment in the clock display.
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but there are other methods in clock display.
And by their description they do what you want to accomplish.

Or maybe you are meant to ADD the increment method?
Is the clock display your code or a provided library?
 
Stephen Corrad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to add a public void addMinuteToTimeOfEvent() method that calls the timeOfEvent's increment () method in the class HistoricalMoment. Clock Display class and HistoricalMoment class are all the class I have.
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.
And as you have pointed out, timeOfEvent is a ClockDisplay.
ClockDisplay does not have an increment method.
Therefore timeOfEvent does not have an increment method.

So you cannot accomplish the instructions literally in this manner.
I would lean towards either incorrect or misinterpreted instructions.
Do the instructions actually say "call the increment method" or do they say "increment the clock" ?

I draw your attention to this comment in the ClockDisplay class:
----------------
This method should get called once every minute - it makes the clock display go one minute forward.
----------------
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!