My simple program to calculate distance by using seconds
Posted: 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 ).
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 
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 ");
}
}
}

