473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Array race result input from user

Hi guys I have been asked to program; Allow the user to enter a number of race results (A minimum of two participants can run in a race and a maximum of 7).

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
  1.         System.out.println("Please input the number of race entrants: ");
  2.         //request number of race entrants
  3.         int TotalEntrants = input.nextInt();
  4.         // allows user to enter number of runners
  5.  
  6.         Runner[] RaceEntrants = new Runner[TotalEntrants];
  7.         //declares and instantiates Runner array
  8.  
  9.         for (int i = 0; i < RaceEntrants.length; i++)
  10.         {
  11. int x;
  12.             //declaring int for entrants number as array starts on 0
  13.             x=i+1;
  14.             //adding 1 to x on every loop
  15.             System.out.print("Please enter race entrant #" + x + "'s name? ");
  16.             String name = input.next();
  17.             //Gathering name
  18.             System.out.print("Please enter race entrant #" + x +  "'s time? ");
  19.             double time = input.nextDouble();
  20.             //Gathering time
  21.             RaceEntrants[i] = new Runner(name, time);
  22.             //RaceEntrants array will hold a name and time for every runner
  23.         }
Dec 11 '19 #1
1 1573
dev7060
630 Expert 512MB
A minimum of two participants can run in a race and a maximum of 7
a value between 0.00 &
10.00 mins.
The code has no condition checks for these.

- The posted code is incomplete. There is no Runner class here.

- Declarations are done inside the loop body. It means new variables are declared in each iteration. Is this necessary?

- Plus, there exist many errors in the code.
Dec 11 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John Davis | last post by:
<html> <body> <Form action="calc.asp" method="post" name="calc"> <P>NUM1: <input type="text" name="num1"> <P>NUM2: <input type="text" name="num2"> <P>RESULT: <input type="text" name="result">...
1
by: Bruce Collie | last post by:
Hi, I want to bind an array to the following sql statement using oci SELECT UUID FROM TEST WHERE TYPE=:VAL UUID is INTEGER TYPE is CHAR(1) If i use obndrv it only ever seems to use the...
2
by: Louis | last post by:
What I am trying to do seems simple, but I haven't figured out how to do it. I need to add the contents of the cells in one array, subject to the values in another array. Normally I would utilize...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
15
by: Carramba | last post by:
hi! I am trying to confirm if input is digit, so I thought it would by easy to do it with with isdigit() funktion, but how do I pass arrays to it if the imput is more then 1 sign? #include...
6
by: GMM50 | last post by:
I've got a project that has 100 settings. In C I've defined these settings in an array: #define SETTING_MAX 100 int Setting; The user refers to them as setting through setting. Internally...
0
by: Vincent Finn | last post by:
Hi, I have a user control and I want an array of items to be available to the user In my case these items are a class called Needle. I added a property called Needles to get\set the array...
4
by: roxorsoxor2345 | last post by:
I have this custom string class that I have created. #include <cstdlib> #include <iostream> using namespace std; class Cstring { private:
5
by: shashi59 | last post by:
Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.