My simple program to calculate distance by using seconds

Java programming topics
Post Reply
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

My simple program to calculate distance by using seconds

Post by Nipuna » Tue Aug 09, 2011 12:47 pm

I made a little program getting the idea how to calculate distance of one direction by using echo time and then how to convert that to feet.

I got the idea from my reference book, that is Java a beginner's guide.

Enter the echo time in seconds then you will get the answer(Enter as an argument. Because i still didn't learn how to get inputs whiteout using arguments ). ;)

Code: Select all


/*
This program finds the distance of one palce to another using echo time of sound.
Gets values as an argument. Enter the value in seconds.
*/

class SoDisCal{

public static void main(String args[]){

	try{

		double time=Double.parseDouble(args[0]); //Gets the argument
		
		if(time==0){
		
			System.out.println("There is no distance then or you can't count the time");
		
		}
		
		else{

		time=time/2; //Divide by 2 to get the distance of a one direction.

		time=time*1100; //Converts to feet

		System.out.println("Distance to the Object is " +time+" feet away!!!");
		
		}
		
		}
		
	catch(NumberFormatException e){ 
	
		System.out.println("Fool! enter the amount(That means seconds) in number format ");
		
		}
	

}
}


My main goal is to read the book completely and then make programs using GUIs. By using GUIs they look great. Even a small program like this looks professional ;) And user friendly too :)
Last edited by Nipuna on Tue Aug 09, 2011 7:49 pm, edited 1 time in total.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: My simple program to calculate distance by using seconds

Post by Neo » Tue Aug 09, 2011 1:23 pm

Nice one... Go ahead!!!
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: My simple program to calculate distance by using seconds

Post by Nipuna » Tue Aug 09, 2011 1:34 pm

Thanks friend :)

:yahoo: :yahoo: :yahoo: :yahoo: :yahoo: :yahoo: :yahoo: :yahoo:
Post Reply

Return to “Java Programming”