#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Desperate for Help


    Hi guys, brand new member here and in my freshman year at SUNY Oswego. I have a project that is due tomorrow and I am in desperate need for help. Here is what I need to do.

    Problem
    We want an application developed to process data from a marathon race. We need to produce who won and who came in last. This program will take in data on individual runners for a race and tells us once they are all processed, not only who the fastest runner was, but also who the slowest was.

    Input
    This will be the first assignment where you will process data stored in a file. The reason for this is simple, when we need to process a substantial amount of data, it simply is easier to have data in a file than it is to type each individual entry in one at a time when prompted for it by the program. Just think about the process of debugging a program where each time you make a small correction/change, you would then run the program again and within seconds see if your changes or corrections did what you expected.
    In this data file, in each line of it, we put in four pieces of information. The individual runnerís number which you can assume to be unique to that runner, the time the runner ran the marathon, in hours, minutes, and seconds. Runnerís number, the hours and minutes are going to be integer values and seconds is going to be a double.
    So, here is an example:
    109 2 15 9.5
    112 3 55 10.4
    211 4 1 56.5

    The first number on each line is the runnerís number, the 2nd number is the hours, 3rd is the minutes, and the last number is the seconds. You may assume there is at least one valid runnerís data in the data file.
    Data Validation
    To make sure we only work we correct information, we are going to display any runnerís data that does not conform to what we consider valid and then discard that runnerís information and not use it in our process. A message is displayed about the runnerís data being bad and the runner. So, unlike the first assignment where invalid data caused the program to abort, here, we just donít use the bad data and go on and process everyone elseís data that is valid. That said, we still wonít deal with incorrect data types entered and will let the program die/abort if the data entered is of an invalid type. For example, if a double value is entered when we expect an int, the program blows up and thatís ok.

    What then constitutes valid and what constitutes invalid then? Weíll focus on minutes and seconds and make the assumption that whatever the number is that has been entered for the runnerís number and runnerís hours is fine; so, if the runner ran the marathon is 55 hours+, we donít care, he was just a little slower than everyone else. On the other hand, we are going to expect the number of minutes to be between 0 and 59 and the number seconds to be zero or more but less than 60.

    Process
    Your program needs to follow a basic algorithm:
    Open the file with runner data
    Initialize a set of variables for fastest and a different set of variables for slowest
    While there is data {
    Read information for a runner
    If the data is valid
    If faster than the fastest
    Replace fastest with the runner just read
    End-If
    If slower than the slowest runner
    Replace slowest with the runner just read
    End-If
    else
    output who the runner was and their time that was in error
    End-If
    }
    Output the fastest and slowest

    There are definitely easier ways of determining which runner is faster than trying to compare hours, then minutes, and the seconds of the time for each runner. Think about that.

    Output
    The output needs to be in the form of the example shown below:

    The fastest runner is XXXXX with the time XX:XX:XX.X
    The slowest runner is XXXXX with the time XX:XX:XX.X
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0
    What have you done so far?

    I think people will be more likely to help you if you attempt it and then when you get stuck ask specific questions about why your code won't work.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    So far I have assigned variables for the runners number, hours, minutes and seconds. I also made a fastest and slowest time so once the loop starts it has something to compare to. I just dont know how to start the while loop
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0
    Originally Posted by Coxy810
    So far I have assigned variables for the runners number, hours, minutes and seconds. I also made a fastest and slowest time so once the loop starts it has something to compare to. I just dont know how to start the while loop
    Well you assignment says you need to read in the runners from a file. Set that up. Your loop should go as long as there are runners to grab from the file.

    so you should have something like

    while(<runners in file to read>){
    check if the new runner is either the fastest of the slowest if so update

    else don't worry about that runner

    }
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    How would I go about telling the loop to read the first part of the string, store it. Then the second part, store it. So on
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0
    My guess is you're suppose to use the Scanner class.

    Once you have a scanner declared you can use methods such as next() nextLine() and hasNext()

    Look through your class notes. I'm sure your teacher showed you how to declare a scanner and take in a file.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    I just want to know how to grab the first part of the text file, which is 5 numbers and store it somewhere.

IMN logo majestic logo threadwatch logo seochat tools logo