Calculate speed , distance and time | Java Program to calculate speed distance and time ; Function to calculate speed ; Function to calculate distance traveled ; Function to calculate time taken ; Driver code ; Calling function cal_speed ( ) ; Calling function cal_dis ( ) ; Calling function cal_time ( )
class GFG { static double cal_speed ( double dist , double time ) { System . out . print ( " Distance ( km ) : " + dist) ; System . out . print ( " Time ( hr ) : " + time) ; return dist / time ; } static double cal_dis ( double speed , double time ) { System . out . print ( " Time ( hr ) : " + time) ; System . out . print ( " Speed ( km / hr ) : " + speed) ; return speed * time ; } static double cal_time ( double dist , double speed ) { System . out . print ( " Distance ( km ) : "+ dist) ; System . out . print ( " Speed ( km / hr ) : " + speed) ; return speed * dist ; } public static void main ( String [ ] args ) { System . out . println ( " The calculated Speed ( km / hr ) is : "+ cal_speed ( 45.9 , 2.0 ) ) ; System . out . println ( " The calculated Distance ( km ) : "+ cal_dis ( 62.9 , 2.5 ) ) ; System . out . println ( " The calculated Time ( hr ) : "+ cal_time ( 48.0 , 4.5 ) ) ; } }