0

Help with writing a Java method that includes a loop and array

I am trying to write a Java method code as follows: A recordNewRun() method which can be called each time a runner completes a park run. This method increments an instance variable that counts the number of runs completed by a runner. The method is passed the name of the park in which the run took place and the time the runner took to complete a 5km run. Data for each new run should be stored in an array for runParks and runTimes. Include methods like - fastest,slowest and average run times.

5th Apr 2018, 1:42 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
34 Answers
+ 2
@ Gordie. thanks . but next time first notify me , before changing my posts šŸ˜ I know the risks
5th Apr 2018, 6:55 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 2
. sorry I thought it was u .... I really don't like that someone else can change the postes
5th Apr 2018, 6:58 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
i don't know how u wrote the code . but I think maybe it's better if u create a class for run (that has fields for time , park .....) then create an array of that class's type to store the runs. then for calculating the fastest , slowest u can iterate through the array , getting the time of each run an comparing them
5th Apr 2018, 2:35 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
Ginjahh Freshh Gyal yes u can (it's called an inner class) if u want , u can mail it to me .... but if your code is not commented , there is not much that I could do to help
5th Apr 2018, 2:43 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
right now I'm heading to work. I'll take a look at it whenI get the chance. hope I could help and learn something :) here: <removed>
5th Apr 2018, 2:57 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
@Farshaad. Okay, I will send you an email now
5th Apr 2018, 2:59 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
+ 1
@ Gordie. Thanks for your advise but sorry I donā€™t understand how to do that?
5th Apr 2018, 7:45 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
+ 1
@ Gordie. Sorry, I am new on here but that sounds like a good idea actually ... I may give that a try. If I can successfully do that, will you take out some time to review my code and see if you could help me with the problem I have?
5th Apr 2018, 8:32 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
+ 1
@ Gordie. Hmm okay, thank you for your advice. Iā€™ll have this in mind
5th Apr 2018, 9:08 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
+ 1
@Gordie. Hmm okay, I shall try what you just said. Hopefully it works out well for me .... Nevertheless, Thank you very much for your help and inputs on this. I appreciate it!
5th Apr 2018, 8:34 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
Thereā€™s more to this but I have already written the code and it runs successfully ... it is also pretty long, I donā€™t Think I have enough space to write it in here
5th Apr 2018, 1:43 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
then where do u have troubles?!
5th Apr 2018, 2:26 AM
Farshaad Heydari
Farshaad Heydari - avatar
0
@farshaad. Iā€™m having troubles calculating the fastest, slowest and average run times inside the recordNewRun() method using a loop and storing the data in the runParks and runTimes arrays
5th Apr 2018, 2:28 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@ farshaad. Is it possible to create the class in another class? Because I already have a class called ParkRunner with a constructor and Get and Set Methods. I donā€™t know if it is possible to create the Run class below the ParkRunner class? ... I would love to show you my code so far but it is too long to write it here
5th Apr 2018, 2:39 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@ farshaad. Yes the code is commented, at least most part of it ... I can email it to you yes. Whatā€™s your email please?
5th Apr 2018, 2:45 AM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@ Gordie. I wrote the ParkRunner code myself but I donā€™t know how to write it in here along with the ParkRunnerTest for people to see. Iā€™m new here ... And writing to a file is part of what I have to do. The RecordNewRun is not a class, it is a method I need to implement in the ParkRunner which I donā€™t know how to.
5th Apr 2018, 6:00 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@Gordie. Okay I shall check your Code Playground. & yes those 2 lines of code in the ParkRunnerTest is a class. But it has to be a method in my ParkRunner which will calculate the fastest, slowest and average time of a park run ... it is really more understanding if you saw my ParkRunner code and the description brief of what I have to do though.
5th Apr 2018, 6:15 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@Gordie. Yes the information is about several runners but Iā€™ll be just fine if it represents for just 1 runner. Yeah I did do methods for sum, average and fastest/slowest. I just did that on my laptop. Iā€™ll just paste my ParkRunner code in my Code Playground for you to see. Give me a few minutes to do that
5th Apr 2018, 6:26 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
0
@ Gordie. Okay Iā€™ve managed to paste in my ParkRunner code in my ParkRunner Java Program in my Code Playground ... it is the first pieces of code you see and then when you scroll down, the ParkRunnerTest code is under it. Hope it helps you understand better.
5th Apr 2018, 6:40 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar
5th Apr 2018, 6:41 PM
Ginjahh Freshh Gyal
Ginjahh Freshh Gyal - avatar