I'm working with on a LinkedList assignment, however I've written the methods for splitting the list into two equal lists, but when I apply the average it only applies it to the first half of the list. When I try to calculate the average before I split the list, it gives me a null error, but I know I wrote the method correct because it works if I calculate the average after.

Here is my code.

Code :

import java.util.Random;
public class TestLinkedList{
public static void main(String[] args){
UnorderedLinkedList list = new UnorderedLinkedList();
int sum=0;
Random rand = new Random();
for(int i = 0; i<59; i++){
int randomNum = rand.nextInt(100)+1;
sum = sum + randomNum;
list.insertLast(new IntElement(randomNum));
}
System.out.println("Printing the list.");
list.print();
System.out.println("Deleting the first node.");
list.deleteFront();
list.print();
System.out.println("Deleting the last node.");
list.deleteLast();
list.print();
System.out.println("Inserting node into the front with a number of 68.");
list.insertFirst(new IntElement(68));
list.print();
System.out.println("Inserting node into the back with a number of 75.");
list.insertLast(new IntElement(75));
list.print();
System.out.println("Now splitting the list into to two equal lists.");
list.splitMid(list);
list.print(); //shows the first half of the list
System.out.println("The average is " + list.average());
System.out.println(sum/59);
System.out.println();
}
}

edit: I just figured out by using the constructor I can make a copy of the list. I was trying to copy using LinkedList object when it's abstract instead of creating a Unordered object. My average method is having trouble. It keeps cutting off the last node's number. Why is it doing this? I'm trying to figure out how to fix it.

It is easier to find problems and give advice if you provide a detailed explanation about what the code is doing, what you want it to do, and any error messages you may have. To say some number of things "aren't working anymore" is not very descriptive. Though it does suggest these things did work before. Which suggests there may be some code recently changed and caused them to stop working. But that is the best I have to offer without more to go on, or spending hours racking my brain too.