help with watch program

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 25
Reputation: shubhang is an unknown quantity at this point 
Solved Threads: 0
shubhang shubhang is offline Offline
Light Poster

help with watch program

 
0
  #1
Dec 5th, 2008
Please help me with a simple watch program.
In the program,I have to display on the same line.
i have written the following code which is not working.
pls look into it
class watch
{
	private int h,m,s,a=0,b=0;

	public void calc()
	{
		
		for(;a==b;s++)
		{
			if(s%60==1)
			{
				m++;
			}

			if(m%60==1)
			{
				h++;
			}

			System.out.println(h+" : "+m+" : "+s);

			Thread.getThread().sleep(1000);
		}

	}
	public static void main(String args[])
	{
		watch w1=new watch();
		w1.calc();
	}

}
The highlighted statement gives an error.
pls help me with the logic of displaying it on the same line.
thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,210
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: help with watch program

 
0
  #2
Dec 5th, 2008
Let me guess "un-catch exception". Put that section in try/catch exception and catch InterruptedException (API)
Last edited by peter_budo; Dec 5th, 2008 at 2:08 pm. Reason: add link
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,484
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: help with watch program

 
0
  #3
Dec 5th, 2008
Rather I would say the error is from calling methods that do not exist on the Thread class.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 63
Reputation: alsoumhi is an unknown quantity at this point 
Solved Threads: 0
alsoumhi alsoumhi is offline Offline
Junior Poster in Training

Re: help with watch program

 
0
  #4
Dec 6th, 2008
first of all, what is the value of variable (s) here in the program, it is assumed here as it is zero , is it the value that you want it or not

secondly the looping will be infinite because value of variable (a) and value of variable (b) is always same , therefore check it again to make the loop finite

hope it helps
thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 254
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: help with watch program

 
0
  #5
Dec 6th, 2008
Hello, shubhang.
You've asked:
pls help me with the logic of displaying it on the same line.
Here is a few articles about positioning cursor in console application:
http://mindprod.com/jgloss/console.html
http://en.allexperts.com/q/Java-1046...or-console.htm
http://www.rgagnon.com/javadetails/java-0469.html
Hope it can help
Last edited by Antenka; Dec 6th, 2008 at 3:26 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC