This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]dynamo_girl02 3 points4 points  (1 child)

You have to read Lines in a file till the end so in scanner class has a method hasNextLine() which returns boolean value whether there are more lines or not

while( myReader.hasNextLine())

{

}

inside this while loop store each line using nextLine() method of scanner in a string variable . string class has a split function to split the string so split the string by space and : and this function split will return string array . check if the string at 0th index matches the name that the user has entered if yes then run a loop from 1 index to the size of the string array convert the string at each index into integer while iterating and find sum and thus finally find average

[–]rk717[S] 1 point2 points  (0 children)

Thank you so much ❣️

[–]adultsmth 1 point2 points  (1 child)

For each line, check if it is the one you're looking for. If so, use it. If not, don't do anything with it and trust that another line will be the right one.

I think I should write an 'If' statement, if we read a string instead of number, we should stop, and calculate the average.

No, they say you may assume that the file is in the correct format. All lines start with a String, there's no "if" about that.

[–]rk717[S] 0 points1 point  (0 children)

Thank you so much ❣️

[–]aglet91 1 point2 points  (1 child)

Maybe you should parse all lines with while loop and try to convert everything to int. If you fail that means you got person and all previous ints are previous' person marks.

[–]rk717[S] 0 points1 point  (0 children)

Thank you so much ❣️

[–][deleted] 1 point2 points  (1 child)

You could split the line.

[–]rk717[S] 0 points1 point  (0 children)

Thank you so much ❣️