I’m trying to get this loop to put each line from a file in an object, then store each object in an arrayList. For some reason the loop stores the first three lines of the input correctly, but when it gets to the last line every item in the array list becomes the values in te last line. I pasted the relevant part of my code below, any suggestions?

```
while (lineIteration != null) {
   //store polynomial objects from Polynomial class in an array list.
    ta.setText(ta.getText() + lineIteration + "\n"); //prints the input to 
                                                     // the text area
    Polynomial objLine = new Polynomial(lineIteration); //store a line in the 
                                                        // objLine object
    System.out.println(objLine);
    polyArrayList.add(objLine); //add the object to the arrayList
    lineIteration = inBR.readLine(); //read the next lineIteration.
    }

```

The full code is below. 
 /\*\*\*\*\* CLASS Main.java \*\*\*\*\*/

```
import java.util.Iterator;

public class Polynomial implements Iterable, Comparable{

    private static String poly;

    public Polynomial (String x){ // constructor that accepts the input and stores it in a polynomial.
        poly = x;
        return;
    }

    @Override
    public String toString() {
        return poly;
    }

    private static class Node<String>{

        private String data;
        private Node<String> next;
        public Node (String data, Node<String> next){
            this.data = data;
            this.next = next;
        }
    }
    @Override
    public Iterator iterator() {
        return null;
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }
}

/****Polynomial.java****/

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.logging.Logger;

public class Main extends JFrame implements ActionListener {
    JMenuBar mb;
    JMenu file;
    JMenuItem open;
    JTextArea ta;
    static ArrayList<Polynomial> polyArrayList = new ArrayList<>(); //ArrayList of objects Polynomial
    Main(){
        open = new JMenuItem("Open File");
        open.addActionListener(this);
        file = new JMenu("File");
        file.add(open);
        mb = new JMenuBar();
        mb.setBounds(0,0,800,20);
        mb.add(file);
        ta = new JTextArea(800,800);
        ta.setBounds(0,20,800,800);
        add(mb);
        add(ta);
    }
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == open) {
            JFileChooser fc = new JFileChooser();
            int i = fc.showOpenDialog(this);
            if (i == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fc.getSelectedFile();
                String filepath = selectedFile.getPath();
                try {
                    BufferedReader inBR;
                    inBR = new BufferedReader(new FileReader(selectedFile));
                    String lineIteration = inBR.readLine();
                    while (lineIteration != null) {
                        //store polynomial objects from Polynomial class in an array list.
                        ta.setText(ta.getText() + lineIteration + "\n"); //prints the input to the text area
                        Polynomial objLine = new Polynomial(lineIteration); //store a line in the objLine object
                        System.out.println(objLine);
                        polyArrayList.add(objLine); //add the object to the arrayList
                        lineIteration = inBR.readLine(); //read the next lineIteration.
                    }
                } catch (FileNotFoundException fileNotFoundException) {
                    System.out.println("File not Found");
                } catch (IOException ioException) {
                    System.out.println("IO Exception");
                }
                System.out.println(polyArrayList.get(0));
                System.out.println(polyArrayList.get(1));
                System.out.println(polyArrayList.get(2));
                System.out.println(polyArrayList.get(3));
            }
        }
    }
    public static void main(String[] args){
        System.out.println("Start");

        Main om = new Main();
        om.setSize(500,500);
        om.setLayout(null);
        om.setVisible(true);
        om.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

}

```