title: How to store multiple variables from a File Input of unknown size in Java?
body: <p>I'm a total beginner with my first programming assignment in Java.
  For our programming assignment, we will be given a .txt file of students like so:</p>
  
  <p>My problem is: I have a specific class for turning the data from the file into variables to be used for a different class in printing it to the screen. However, I do not know of a good way to get the variables from the input file for the course numbers, since that number is not predetermined. The only way I can think of to iterate over that unknown amount is using a loop, but that would just overwrite my variables every time. Also, the teacher has requested that we not use any JCL classes (I don't really know what this means.)</p>
  
  <p>Sorry if I have done a poor job of explaining this, but I can't think of a better way to conceptualize it. Let me know if I can clarify.</p>
  
  <p>Edit:</p>
  
  <pre><code>public static void analyzeData()
  {
      Scanner inputStream = null;
  
      try
      {
          inputStream = new Scanner(new FileInputStream("Programming Assignment 1 Data.txt"));
      }
  
      catch (FileNotFoundException e)
      {
          System.out.println("File Programming Assignment 1 Data.txt could not be found or opened.");
          System.exit(0);        
      }
  
      int numberOfStudents = inputStream.nextInt();
      int tuitionPerHour = inputStream.nextInt();
      String firstName = inputStream.next();
      String lastname = inputStream.next();
      String isTuitionPaid = inputStream.next();
      int numberOfCourses = inputStream.nextInt();
      String courseName = inputStream.next();
      String courseNumber = inputStream.next();
      int creditHours = inputStream.nextInt();
      String grade = inputStream.next();
  </code></pre>
  
  <p>To show the methods I am using now, I am just using a Scanner to read from the file and for Scanner inputStream, I am using nextInt() or next() to get variables from the file. Obviously this will not work when I do not know exactly how many classes each student will have.</p>