• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program that inputs finishers at a marathon and outputs the top 3 finishers. Java using arrays  RSS feed

 
peter yambao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me i am trying my best to do this program but I cant just do it. can you guys give me codes for me to use?
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that we are NotACodeMill and you should at least ShowSomeEffort. Thanks!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks here will bend over backwards to HELP you LEARN how to do it yourself.

The best advice is to follow these instructions:

1) turn off your computer
2) Get pencil and paper.
3) write down the steps how YOU would do it, using only pencil and paper.
4) Revise the above steps until it is crystal clear what should be done at every step
5) Revise them 4-5 more times, clarifying and simplifying each and every item.
6) When you think you are done, and there is no ambiguity in what should be done, show those steps to a 10 yr. old child and see if they can follow them.
7) Revise the instructions until they can.

Only when you have done all the above should you consider writing a single line of java.
 
peter yambao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here is my code. Im not asking you to give me the whole code, Im just asking you guys to help me because im a beginner, why do you have to be rude? anyway is there something you can "GIVE" or "ADVISE" me to change my code for me to get the name and the time paired? I dont know how to use insertion sort, could you help me please?
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, when posting code snippets use the code tags. So the code is well formatted and thus easier to read. I did it already for you in your previous post.

peter yambao wrote:anyway is there something you can "GIVE" or "ADVISE" me to change my code for me to get the name and the time paired?

Maybe you can have a look at the Map interface and the implementing classes HashMap, TreeMap,...

And you don't need to declare a loop counter in advance, you can declare it in the for-loop itself, like this:

 
peter yambao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of my friends say use insertion sort for me to sort the name of the runner and the time together, but I don't know how to use that. should I just replace the array.sort with it? im still currently studying java so im still getting a hard time ti figure things out.
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I would do to implement "FunRun 2013":
  • create a class (e.g. Participant) to hold name & finishing time of a runner
  • create a Comparator for sorting the participants on the finishing time


  • If you have those 2 components it will be easy to create your program:
  • write a loop that allows a user to input all participants, for each participant you create a new Participant instance and populate name & finishing name with the data provided by the user and store this participant in a list. You exit the loop when the user enters an empty runner name.
  • sort the list with participants using the Comparator
  • print the first three items from the list with participants


  • Good luck!
     
    Roel De Nijs
    Sheriff
    Posts: 11338
    177
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I followed my own instructions and based on this input I got the desired output.

    Input:
    Roel
    200
    Peter
    365
    Koen
    198
    Stevie
    241
    Frankie
    316
    Usain
    175
    <empty line>


    Output:
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!