title: How to create my own single linked list
body: <p>I am trying to convert code that works with ArrayLists into code that will work for singly linked lists. The array list is made up of Shape objects that are created previously and I know work. Then, the new shapes can be added on to the end of the array list. Also, specific shapes can be removed from this list using the index reference. However, when I switch this to a linked list, I'm not getting quite what I need. Here's the code for the array list:</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class ShapeLinkedList {
      ArrayList&lt;Shape&gt; list = new ArrayList&lt;Shape&gt;();
  
      public ShapeLinkedList() {
      }
  
      public void addToRear(Shape shape) {
          list.add(shape);
          System.out.println("Added "+shape);
      }
  
      public Shape get(int index) {
          return list.get(index);
      }
  
      public int size() {
          return list.size();
      }
  
      public Shape remove(int index) {
          Shape temp = list.remove(index);
          System.out.println("Removed "+temp);
          return temp;
      }
  }
  </code></pre>
  
  <p>I cannot alter the names of the methods and I must use all of the same methods. So this is what I have so far for the linked list:</p>
  
  <pre><code>public class ShapeLinkedList {
      ShapeNode head;
      int count = 0;
  
      public ShapeLinkedList() {}
  
      public void addToRear(Shape shape) {
          ShapeNode end = new ShapeNode(shape);
          if (head == null) {
              head = end;
          }
          //loop through Linked List until we find the end of the list
          while (head.next != null) {
              head = head.next;
              count++;
          }
          //set the new node to the Shape shape and the next one will be null
          head.next = end;
          count++;
          //System.out.println("Added " + shape);
      }
  
      public Shape get(int index) {
          for (int i = 0; i &lt;= index; i++) {
  
          }
          Shape rem = ;
          return rem
      }
  
      public int size() {
          return count;
      }
  
      public Shape remove(int index) {
          if (index == 0) {
              Shape temp = head;
              head = head.next;
          } else if () {
              Shape temp = ;
          }
          //System.out.println("Removed " + temp);
          return temp;
      }
  
      private class ShapeNode {
          Shape shp;
          ShapeNode next;
  
          public ShapeNode(Shape shp) {
              this.shp = shp;
              next = null;
          }
      }
  }
  </code></pre>
  
  <p>I need help constructing the getter for the Shape because I do not know how to find the index of the LinkedList and I do not know how to reference the specific shape type at that index. Also, I need help with the remove method. I feel like once I get the necessary info for the first getter I'm having trouble with, I should be able to solve my second problem. Does anyone have helpful suggestions?</p>