Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Average Speed Programme

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,739
    My Mood
    Mellow
    Thanks
    233
    Thanked 709 Times in 695 Posts

    Default 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.

Similar Threads

  1. Java programme design help
    By dulitul in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 29th, 2013, 06:06 PM
  2. new member need help in java program(typing speed)
    By almujeda_23 in forum AWT / Java Swing
    Replies: 1
    Last Post: June 29th, 2012, 07:25 AM
  3. Java programme to colour in a grid
    By why_always_me in forum Java Theory & Questions
    Replies: 20
    Last Post: March 29th, 2012, 06:09 AM
  4. can someone show me how to change speed of an java engine.
    By codenoob in forum Java Theory & Questions
    Replies: 19
    Last Post: December 14th, 2011, 11:26 AM
  5. How to speed up the performance of the java application
    By Sathiyan in forum Java Theory & Questions
    Replies: 4
    Last Post: December 2nd, 2011, 01:09 AM