Results 1 to 4 of 4
  1. #1
    rover123 is offline Member
    Join Date
    Apr 2012
    Rep Power

    Unhappy Add two times together

    Hey, i'm very new to Java and this is my first time using it . I'm just curious as to whether someone can help me out with a problem i have. I need the user to enter a start and end time for two different competitions, i then need to add the total time it took for each competition and display the results to the user. So far this is what i have:

    import javax.swing.JOptionPane;

    public class BiathlonSkiingEvent

    public static void main(String[] args)

    String numString1 = JOptionPane.showInputDialog("Enter your sprint start time (MM:SS:TT)");
    String numString2 = JOptionPane.showInputDialog("Enter your sprint end time (MM:SS:TT)");

    int firstNum = Integer.parseInt(numString1);
    int secondNum = Integer.parseInt(numString2);

    int sprintresult = firstNum + secondNum;

    String numString3 = JOptionPane.showInputDialog("Enter your biathlon start time (MM:SS:TT)");
    String numString4 = JOptionPane.showInputDialog("Enter your biathlon end time (MM:SS:TT)");

    int thirdNum = Integer.parseInt(numString3);
    int fourthNum = Integer.parseInt(numString4);

    int biathlonresult = thirdNum + fourthNum;

    JOptionPane.showMessageDialog(null, biathlonresult + sprintresult);


  2. #2
    shall is offline Senior Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: Add two times together

    I think you might want to use the StringTokenizer class as shown at
    StringTokenizer (Java Platform SE 6)

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Add two times together

    Search the net for Joda time; it has a Duration class.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    isuru is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default Re: Add two times together

    try to get the start time and finish time and subtract each other. That way you can get the duration. And compare and make the lowest one win. If you need more help post here.

Similar Threads

  1. Repeating too many times.
    By trishtren in forum New To Java
    Replies: 4
    Last Post: 11-11-2011, 12:20 AM
  2. Using the same image several times: does it eat up more RAM?
    By NuxlyStardust in forum New To Java
    Replies: 4
    Last Post: 08-02-2011, 03:50 PM
  3. Looping WAY too many times...
    By BariMutation in forum New To Java
    Replies: 10
    Last Post: 10-15-2010, 10:27 AM
  4. Times without dates.
    By JavaJuJitZu in forum Advanced Java
    Replies: 14
    Last Post: 01-17-2010, 10:54 PM
  5. Difference in seconds between two times
    By jazzy639 in forum New To Java
    Replies: 11
    Last Post: 09-26-2009, 06:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts