Results 1 to 8 of 8
- 03-07-2009, 09:51 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
Accessor help needed (I think...- little confussed)
Hi Guys, I'm new to java and I'm struggling a bit this semester as we've introduced using a main file and then a driver file.
At the moment I'm trying to get my head around accessor methods.
I've written this code to convert time in seconds into "hours:minutes:seconds" format.
If in another file I set something (either via a scanner, or just a plan int variable with a value of seconds), how can I send it to the TimeDisplay class to return the correctly formatted time?
Many thanks in advance :)Last edited by thomase; 03-12-2009 at 12:49 PM. Reason: removing private code
- 03-09-2009, 05:09 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
It's gone off the first past so I assume it's okay to give it a little bump?
-
If all this class is, is a place to hold your small utility or helper method, this is one of the few places where I think it's OK to use static methods: in other words, you can have a public static method that takes an int (or long?) as input and returns a String as output, and then call it as you would any static method -- on the class, not on an object.
- 03-10-2009, 03:14 PM #4
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
So with that I'd keep what I've got wouldn't I? Then in the main file what would I put? I've had a look on the net for a tutorial, I'm just unsure of how to send the int (not long) from this 'main' file to the TimeDisplay class and then from there, to output it back in the 'main' file.
I'd love a little code snipit or a link to a site where with a bit of work I could decode some code that would do this. Problem at the moment is I see websites and I'm not sure if they do have relevant code, but I've no problem working out how to do it from a code.
-
similar to what you have, except for no constructor and the method is static and takes an int parameter, seconds.
- 03-10-2009, 06:12 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
- 03-11-2009, 03:40 AM #7
Member
- Join Date
- Sep 2008
- Posts
- 13
- Rep Power
- 0
Java Code:// ok in the application class ... public static void main(String[] args) { int seconds = 10001; //here you are declaring and instantiating an object //of the TimeDisplay class and naming it time, you are passing // the seconds variable to the paramaterized constructor TimeDisplay time = new TimeDisplay(seconds); //here you are displaying your output.... by calling the accessor //accessor method displayHrsMinsSecs() on the object reference //time System.out.println(time.displayHrsMinsSecs()); } }
- 03-11-2009, 10:29 AM #8
Member
- Join Date
- Mar 2009
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
help needed
By amarchandar in forum New To JavaReplies: 1Last Post: 02-18-2009, 11:38 AM -
help needed
By amarchandar in forum New To JavaReplies: 3Last Post: 02-17-2009, 01:59 PM -
Trying to understand accessor and mutator methods
By DC200 in forum New To JavaReplies: 6Last Post: 12-02-2008, 11:15 PM -
a little help needed..
By litojs in forum New To JavaReplies: 1Last Post: 11-16-2008, 07:12 PM -
Help needed.
By necro-1000 in forum AWT / SwingReplies: 2Last Post: 01-12-2008, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks