"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Kd Martin wrote:I suppose I am doing this student. The instructions given are somewhat vague and just say that it will add student and have Student student as a parameter. I will be using a driver to test the program. So should I just have course.removeStudent(this.student)?
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Kd Martin wrote:Alright then, I'm not sure of what else to do instead of this.student. Sorry, I'm still new to this.
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Kd Martin wrote:Perfect, thanks so much Riaan Nel! I've solved this problem! Everything compiled perfectly!
"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Paul Clapham wrote:You do that by looking at the code. But first you have to figure out what code to look at: I don't know what method is called when you try to "drop a student", as you say, because I'm not sure if "removeStudent" or "dropCourse" is really where I should be looking. So that would be your first step.
Kd Martin wrote:Ok. So I should be able to create courses and students and drop and add courses. Everything correctly compiles and I can create objects, but every time I try to add a student, the method returns false, and as soon as I try to drop students from courses, I get a null pointer exception. I'm assuming I get this because Students are not being added correctly in the first place, but I can't figure out why that would be.
Paul Clapham wrote:
We determined that it's false. So it's not the case that the currentEnrollment variable is less than the capacity variable. And you're going to be surprised by that because you expected currentEnrollment to be zero initially and capacity to be some positive number which is the size of an array. But if that's how it was, then that boolean expression would be true. And it's false. So now you have cognitive dissonance because that wasn't what you expected. This is the time to believe what the computer says, regardless of what you think should be the case. Something is fishy about one or both of those two variables at run time, so now it's time to do some debugging and find out just what their values are when you call that method.
Paul Clapham wrote:Yes, the way you wrote addStudent and removeStudent is a sure-fire way of producing NullPointerExceptions.
Kd Martin wrote:
Paul Clapham wrote:Yes, the way you wrote addStudent and removeStudent is a sure-fire way of producing NullPointerExceptions.
What do you mean by this?
And I'm not sure how to go about debugging a project this large with print statements
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|