title: Create object in an ArrayList from textfile input in java
body: <p>I have a text file of a list of Students that lists last name, first name, lab grade, project grade, and exam grade, for example:</p>
  
  <pre><code>Owens Will 46 54 56  
  Smith John 44 77 99
  </code></pre>
  
  <p>I am trying to write a method that reads the textfile, uses each line to create a Student object and then adds that to an ArrayList of Students. A Student object consists of the first name, last name, lab, project, and exam grades.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>private ArrayList&lt;Student&gt; arraylist = new ArrayList&lt;Student&gt;();
  
  public void ReadFile(String inputfile) throws FileNotFoundException {
      File myFile = new File(inputfile);
      Scanner sc = new Scanner(myFile);
  
      while (sc.hasNextLine()) {
          arraylist.add(sc.nextLine());
      }
  }
  </code></pre>
  
  <p>I'm unsure of how to create the Student object from the text file and then unsure of how to place the objects into the ArrayList?</p>
  
  <p>EDIT:</p>
  
  <p>Here's my Student class:</p>
  
  <pre><code>public class Student {
      // fields
      private String firstname;
      private String lastname;
      private int labgrade;
      private int projectgrade;
      private int examgrade;
      private int totalgrade;
  
      // constructor
      public Student(String firstname, String lastname, int labgrade,
          int projectgrade, int examgrade) {
          this.firstname = firstname;
          this.lastname = lastname;
          this.labgrade = labgrade;
          this.examgrade = examgrade;
          this.totalgrade = labgrade + projectgrade + examgrade;
      }
  
      // method
      public String toString() {
          String s = firstname + " " + lastname + " has a total grade of "  + totalgrade;
          return s;
      }
  }
  </code></pre>