Java Average Speed Programme
Hi. I new to java - I have previously programmed in C. However I was wondering if someone could help me with this Lab task I have to do.
"The program is to compute and report the average speed of a vehicle over a distance of one mile, given the times at which the vehicle passed cameras at the start and end of the measured mile.
Input to the program should come from the keyboard. The first line contains the time at which the vehicle passed the first camera, represented in the form hh mm ss, using the 24 hour clock. The second line contains the time at which it passed the second camera, in the same format. The user should be prompted to provide each line of input. The output should be the average speed of the vehicle in miles per hour, represented as an integer.
For example, for the input dialogue
Type the first time: 17 23 56
Type the second time: 17 24 56
the corresponding output would be
Average speed = 60 mph."
I am unsure the best way to read in the time...should it just be an int? Then how do I use the int to calculate the time difference.
Once I have the time difference calculated working out average speed is easy.
Thanks in advance.
Re: Java Average Speed Programme
Reading the time from the keyboard as 3 int values should work. I don't know if that's the "best way," but it's a way and might provide the quickest starting point from which to do the difference calculations. Give it a try.