reset password
Author Message
KA1997
Posts: 31
Posted 22:48 Apr 10, 2017 |

In the getLowestScore and getSecondLowestScore methods, how do you compare all 10 values to get the lowest and second lowest scores?

jgarc659
Posts: 27
Posted 23:37 Apr 10, 2017 |

 

 

Last edited by jgarc659 at 01:10 Apr 11, 2017.
jgarc629
Posts: 76
Posted 19:42 Apr 12, 2017 |

I found out how to get the lowest but how can I find the second lowest? Do I have to involve the lowest in that method?

KA1997
Posts: 31
Posted 23:55 Apr 12, 2017 |
jgarc629 wrote:

I found out how to get the lowest but how can I find the second lowest? Do I have to involve the lowest in that method?

I was never able to figure out second lowest either

sdo8
Posts: 54
Posted 00:58 Apr 13, 2017 |

I used a string accumulator for getting the two lowest scores.

Every score that is inputted by the user is added to a string accumulator.

Once the user was done adding scores, the accumulator would have 10 numbers + 10 spaces after each number.
The spaces are extremely important because they help me identify what each score is. They also help later on in the code when taking out each number.

I then create a new string y that temporary stores information.

I also create an integer x with the highest score at 100.0.

Since the string accumulator is a string, I can use a for loop and iterate for each charAt(i) until the length of the accumulator.
I use the new string to store each character until it hits a ' ', or space. When the program runs into a space bar, the string is converted into an integer and tested to see if it is less than or equal to x.

If that string converted to an integer is less than x, i change x to that integer. That way, the program will keep checking for the lowest score.
I also reset the temporary string  y back to "", so that it doesn't factor in the previous numbers.

Finding the second lowest score would be to define a new variable, then setting that variable equal to the highest score, before the highest score is converted to the temporary string.

Hope this makes sense.

This would use a method that uses a string parameter and a integer return type.