Write a program that reads in (possibly from a file) a set of Students name and GPA and outputs the name and GPA of the student having the highest GPA. The number of students will be given as an input.
For example, for the following input data:
The output is:
what i'm trying to do is create a class with array variables and then from the main get the values from the file and then send them to the class but it wont work
it is my first time doing array of objects so this is really bad
The 's' array defined on line 18 should be the ONLY array you need. You went a bit overboard turning all your variables into arrays. 'name' for instance is not an array it is a member of the Student class and each Student only has one name. 's' however does hold several Students.
There is something familiar about that assignment; I think somebody else has done the same assignment recently on this forum.
You are not far off; you can fill the array with only sloght changes.
I am afraid, however, you aren't opening anc closing the file correctly. Also File is regarded as legacy code. This part of the Java™ Tutorials tells you the best way to close a Scanner (never close a Scanner reading System.in), to make absolutely sure the file is closed.Notice you don't have to call close(). I would prefer to use NIO2 code (import java.nio.file.Paths):-All this code should be in a class by itself, in separate methods. You have far too much code in the main() method.
You can populate the array in a loop; you should create a Student object and put that into the array; you should most definitely not create parallel arrays, which are very error‑prone. You only need a small change in your loop to get everything working.