Process the results by
• Allowing a user to enter a race participants name
• Allowing a user to enter a race participants completion time (a value between 0.00 &
10.00 mins.)
Is the following code sufficient? or should I go another way about it, any help will be beneficial only started java 3 months ago!
Expand|Select|Wrap|Line Numbers
- System.out.println("Please input the number of race entrants: ");
- //request number of race entrants
- int TotalEntrants = input.nextInt();
- // allows user to enter number of runners
- Runner[] RaceEntrants = new Runner[TotalEntrants];
- //declares and instantiates Runner array
- for (int i = 0; i < RaceEntrants.length; i++)
- {
- int x;
- //declaring int for entrants number as array starts on 0
- x=i+1;
- //adding 1 to x on every loop
- System.out.print("Please enter race entrant #" + x + "'s name? ");
- String name = input.next();
- //Gathering name
- System.out.print("Please enter race entrant #" + x + "'s time? ");
- double time = input.nextDouble();
- //Gathering time
- RaceEntrants[i] = new Runner(name, time);
- //RaceEntrants array will hold a name and time for every runner
- }