help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patson
    New Member
    • May 2007
    • 1

    help

    am trying to do this assignment, but I can't, can some help or coach me thru this.

    Write a program that reads two times in military format (0940, 1705) and prints the number of hours and minutes between the two times. Here is a sample run.

    Please enter the first time: 0940
    Please enter the second time: 1705
    7 hours 25 minutes

    Use a Time class with a constructor that takes an integer-based military time as a parameter and a method difference that takes a Time object as a parameter and returns a Time object.

    Note: The times should be input in the order in which they occur. For example, for 0940 on Monday and 1705 on Monday, the first time is 0940, and the second time is 1705. For 1705 on Monday and 0940 on Tuesday, the first number is 1705, and the second number is 0940.

    Hint: To account for negative time differences, as in the second instance described above, add one day (24 * 60 minutes) to the difference and then find the remainder that results from dividing the result by the number of minutes in a day. That is, timeDifference = (timeDifference + MINUTES_PER_DAY ) % MINUTES_PER_DAY . Note that this calculation will not make a difference in a case of a positive time difference, but it will make the proper adjustment in a case of a negative time difference.
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by patson
    am trying to do this assignment, but I can't, can some help or coach me thru this.

    Write a program that reads two times in military format (0940, 1705) and prints the number of hours and minutes between the two times. Here is a sample run.

    Please enter the first time: 0940
    Please enter the second time: 1705
    7 hours 25 minutes

    Use a Time class with a constructor that takes an integer-based military time as a parameter and a method difference that takes a Time object as a parameter and returns a Time object.

    Note: The times should be input in the order in which they occur. For example, for 0940 on Monday and 1705 on Monday, the first time is 0940, and the second time is 1705. For 1705 on Monday and 0940 on Tuesday, the first number is 1705, and the second number is 0940.

    Hint: To account for negative time differences, as in the second instance described above, add one day (24 * 60 minutes) to the difference and then find the remainder that results from dividing the result by the number of minutes in a day. That is, timeDifference = (timeDifference + MINUTES_PER_DAY ) % MINUTES_PER_DAY . Note that this calculation will not make a difference in a case of a positive time difference, but it will make the proper adjustment in a case of a negative time difference.
    I would start of by getting reading up on Class Time from Java.

    Then decide how many objects you will need.
    then decide how to do the caluations. Which you already have in place.

    nomad

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by nomad
      I would start of by getting reading up on Class Time from Java.

      Then decide how many objects you will need.
      then decide how to do the caluations. Which you already have in place.

      nomad
      Or perhaps java.sql.Time but better is java.util.Grego rianCalendar.

      Comment

      Working...