0

I am trying to create a program for my college marathon . I want to be able start a stopwatch (timer) for every one running the marathon and as each person finishes the marathon i want to type in there id number and stop there Stopwatch (timer) and print out a statement saying ("you finished the marathon in " + (Time).

Just wondering is this possible to create and what way would i go about it . any help would be greatly appreciated

Regards

Niall

Ross Allen
  • 43,772
  • 14
  • 97
  • 95
user3292394
  • 609
  • 2
  • 11
  • 24
  • What language are you using? Please tag it. Also show what you have tried, and what problems you are facing. And _yes_, it _is_ possible – Paul Samsotha Feb 10 '14 at 10:26
  • I am only starting to created it so i have no code to show yet ., Was wondering what would be the easiest language to use ? I have a good knowledge of java,javascript,sql,and a small bass of c++ – user3292394 Feb 10 '14 at 10:50

1 Answers1

0

See this answer for creating a digital clock in Swing.

enter image description here

Though this answer is only a clock, it could easily be made into a stop watch. Make use of the System.currentTimeMillis(). Have a static start time, that is populated to a data structure of a Runner object that will hold name startTime and endTime. For each runner when they're finished, they get their own endTime.

See this question for elapsed time formatting.


UPDATE

There are number of ways you can handle this. One solution is you could store the Runners in a HashMap

 public class Runner {
     long endTime;
     Integer id;

     public void setEndTime(long endTime) {
         this.endTime = endTime;
     }
 }

 public class GUI {
     Map<Integer, Runner> runners = new HashMap<>();

     public GUI {
         Runner runner = new Runner(12334....) // id
         map.put(runner.getId(), runner);
     }
 }

Like I said there are a number of ways to set the end time. One way is to have a endTime variable also in your GUI class. When you click a button, the variable will be assigned. Then in a text field you can type in the runner id, and assign the endtime to the runner in the map that matches the id. So everytime the button is pressed, it will be a new end time set the endTime variable, so each runner will get their own endTime

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720