Welcome to the Ranch, Cody
Try not to post such an amount of code especially when you're trying to solve an issue which appears in a known for you area of code.
Fred already pointed out what causes a problem. However, since you posted all that code, I thought I'll give some comments on it, so you could consider improving it.
1. As an example refering to this your code snippet:
Do you know about the
enhanced-for loop? It is very handy for iterating over collection of items. Example:
2.
This code snippet lets to set
major to null, think how to not let that. How that happens? In case to this method majorName is passed a non existing name, method getMajorByName() would return null. Consider before you setting major if returned value is null - in case it is, let user know (throw an exception), that such major doesn't exist in majors list and can't be set as such.
3. Line 98 in Catalog class has the line:
this line can cause you problems too. Before you parse, check if the next token can be parsed to an integer, in case not, let user know about it, that the courseFile has been passed contains invalid data, so cannot be read and is needed other. Read about the Scanner class method
hasNextInt()
4. Some instance variables aren't private - make them as such. Refering to
Major class.
5. While being an explicit is a sign of good code readability, in the code part like this I think it is a bit too much (others might think differently):
Think if you want to change it to:
Did you notice what I did? It is related with the second issue of that method. This method name suggests that it should add a Student, but it appears in your case it creates/adds and returns. That is not good most likely. If the method says
addSomething it should add and nothing else - ok, it might could return true or false in success or failure, but definitely not return a Student. So I'd keep such method as void (with no return type). In case you need to get student, create another method. One method needs to do one thing (similar issues in similar cases in other classes).
6. Something not quite correct with the line 85 [College class]:
7. Some of the methods starts with an
Upper case while they shouldn't:
methodName;
variableName;
ClassName; CONSTANT_NAME.
That is it for now.