Kelvin Okornoe

Ranch Hand
+ Follow
since Mar 18, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kelvin Okornoe

Junilu Lacar wrote:Same logic as best runner except you skip any element that is equal to the best runner’s time.

Since you already solved best runner, would you like to see how I solved it without using Arrays.asList().indexOf()?



Yes, I will want to see how you solved it..
1 day ago
Getting the logic for the secndBestRunner is proving difficult for me,
My idea is that since I know the best runner, I can remove that item from the array and then find the Best runner again in the new array,
but this idea looks wired to me though.
This is the implementation of the method so far, it gives me arrayIndexOutOfBounds.


Maybe you can help me with a better logic here..
Thank you,
1 day ago

Junilu Lacar wrote:Here's a JUnit test I used to debug your code:

The BestRunner tests pass but all of the SecondBestRunner tests fail: two with an ArrayIndexOutOfBoundsException and one gives an incorrect result, 2 instead of 1.



Thank you Junilu , I have seen where my code gets buggy especially on line 72.
Am still working on it to get the logic right
3 days ago
Wow!, am surprised my code fails with different set of data.

I didn't actually test my code against different data.
I will make the necessary improvement for feedback..
Thank you so much.  
5 days ago

Junilu Lacar wrote:Does it work? I’m not so sure the second fastest logic is correct.



The code works
5 days ago
This is the current state of the program.
5 days ago

Campbell Ritchie wrote:That would work, but why do you want a List in the first place?



That is what I think will work for now, I actually want an array not a list (if there is any different between a list and an array)
5 days ago

Piet Souris wrote:Exactly, and that is why the method always returns -1. It is looking for an Integer in a List of Integer[]. And since an Integer never equals an Integer[], you get that -1.

So, as I said earlier, the 'return Arrays.asList(time).indexOf(fastest) doesn't work. Now, lets for the time being maintain the idea of turning the time array into a List and find the index of fastest. Can you come up with a way to properly convert the time array to a List<Integer>?



Am thinking of declaring an array of type Integer and copy the items from int[] times into it
6 days ago

Piet Souris wrote:hi Kelvin,

I overlooked a very nasty error, that is very easy to make, and that is the reason why your method returns -1.  If x is an int[], then Arrays.asList(x) does NOT create a List of the elements of x. Do you use an IDE? If so, do this at the end of the method:
I use the java 10 'var' here, but hover the mouse over 'var' and let the IDE change it to the real type. What do you notice?



I just checks the documentation, x returns a List of Integer array.... var is the same as List<Integer[]>,
that was the reason why I converted the int[] time to Integer[] time...
6 days ago

Piet Souris wrote:hi Kelvin,

I overlooked a very nasty error, that is very easy to make, and that is the reason why your method returns -1.  If x is an int[], then Arrays.asList(x) does NOT create a List of the elements of x. Do you use an IDE? If so, do this at the end of the method:
I use the java 10 'var' here, but hover the mouse over 'var' and let the IDE change it to the real type. What do you notice?



I have implemented your code, but still the same issue, x returns an object in memory, fastest returns the fastest time and i returns -1

Am thinking what could be wrong?
6 days ago

Junilu Lacar wrote:

Kelvin Okornoe wrote:My idea is to learn and seek guidance when am stack trying to solve a problem


Your perseverance is certainly commendable.

Once you get your program to work, I think it would still be a good learning exercise to see other solutions. This is the approach taken by the authors of the book, "Java by Comparison," who were college professors who wanted to show their students how the programming problems they were given as homework would be solved by professional developers. This is something I do as well when I'm trying to learn a new language; I write my solution and then compare what I did to what other more experienced developers in that language would do. It's quite informative.



Thank you Junilu for your time and words of encouragement, I will continue working hard...
6 days ago

Piet Souris wrote:Bedtime in Holland! Goodnight and I'm very curious to see where we are tomorrow morning.



Thank you soo much Piet, I do appreciate your time and effort....

Still working on it, am also in Ghana
6 days ago

Junilu Lacar wrote:We usually let people work out problems themselves but I think it might help you understand where you're going wrong if you see how other people would solve this. Would you like to keep trying to get your code to work or would you like to see how Piet and/or I (or others, if there's anyone else lurking around here) would solve this?



My idea is to learn and seek guidance when am stack trying to solve a problem
6 days ago

Piet Souris wrote:You must absolutely skip that 'return Arrays.asList(time).indexOf(fastest);'. If you have, for instance, two fastest indices (two people with the same fastest time), then you will miss that other index (why?). And even if you do find a seond fastest index, that Arrays.as... will always return the first index found.


Edit: this reply was sent before I saw your latest code.
Edit 2: in your latest 'bestRunner' the parameter is int[] time, but in Arrays.as... you use times. That works, because you have times as static variable.



Thank you for @Piet for the comments, my current code does not even the index of the fastest time, I am struggling to resolve that then I will go ahead and try implementing your suggestion.
Thank you
6 days ago
I don't why the index of the fastestRunner is not been returned...
6 days ago