Results 1 to 3 of 3
- 05-18-2012, 06:57 PM #1
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
New to Methods -- need help with a counting program
Hi all,
I'm making a class that functions as a counting-based internal clock that can be referenced by other classes.
So far, I have several methods in the clock class. My question pertains to only a few of them, which I've included below.
I've written a test class to see if the internal clock works.Java Code:public class WorldTime { private int timevalue; public Boolean startclock; public void runinternalClock() { timevalue++; try { Thread.sleep(1000); } catch (InterruptedException e) // dummy value so far. { } if (timevalue == 2400) { resetTime(); } } public void motorClock() { while (runTime(true)) { runinternalClock(); } } public int getTime() { return timevalue; } public void resetTime() { timevalue = 0; } public Boolean runTime(Boolean begin) { if (begin) { return true; } else { return false; } } }
However, I've received mixed results in my programming. Sometimes, the while loop fires only once, resulting in a timevalue = 1; other times, the output is 0, meaning the loop hasn't fired at all.Java Code:public class TimeTest { public static void main(String args[]) { System.out.println("Enter a value"); Scanner scan = new Scanner(System.in); int x = scan.nextInt(); if (x > 0) { try { Thread.sleep(5000); } catch (InterruptedException timevalue) // necessary. { } System.out.println("The game's time is: " + openUp()); } } public static int openUp() { TestRun tout = new TestRun(); return tout.testRun(); } } class TestRun extends TimeTest { WorldTime be = new WorldTime(); public int testRun() { be.runTime(true); return be.getTime(); } }
Can anyone provide any advice for me?
Thanks in advance!Last edited by ajfonty; 05-18-2012 at 08:09 PM.
- 05-18-2012, 06:59 PM #2
Member
- Join Date
- May 2012
- Posts
- 3
- Rep Power
- 0
New to Methods -- need help with a counting program
oops, double post.
Last edited by ajfonty; 05-18-2012 at 08:09 PM.
- 05-18-2012, 07:46 PM #3
Similar Threads
-
How do I write this program with classes and methods?
By bossyboy in forum New To JavaReplies: 3Last Post: 10-22-2011, 12:25 PM -
Program working fine until I add methods....
By LadyMonsterFace in forum New To JavaReplies: 3Last Post: 12-04-2010, 03:22 AM -
Incorporating Methods into my program
By Moltisanti in forum New To JavaReplies: 16Last Post: 10-12-2009, 06:48 AM -
Program To Call Random Methods
By nyamtoko in forum Advanced JavaReplies: 5Last Post: 12-01-2008, 11:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks