• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList From Class Data  RSS feed

 
James Rivera
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks in advance for taking the time to read through my issue. I'm working on a project with several classes. Each class contains default and overloaded constructors that are used by a test class to feed data into. Within one of my classes (Student) I've created an ArrayList that uses another existing class (StudentClass) as the data type. When the ArrayList is called toString(), none of the data comes through. I should also mention that I was a bit unsure about how to set up the parameters and variables in the StudentClass constructor, since the arguments from the test class are method calls. I feel like this issues are somehow related but I can't figure it out. Here is the code:

Test Code:


Student:


Person (the super class of Student):


StudentClass:


OfferedClass (the super class of StudentClass):


And here are the rest of the classes that are necessary to make the TestClass run without errors on an IDE:

Faculty:



FacultyClass:


Classroom:


The logger that's printing all of the toString() methods:



When I pass "ArrayList <StudentClass> classes" toString(), I get "0.0, Null, Null" the first time and absolutely nothing the second time.

Any help is greatly appreciated!
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there no way you can condense your code down a little? You've posted an awful lot. Remember to try and use SSCCE. That's helped me especially when others have reminded me so,hope it does with you too

Also remove the white space if you can - there seems to be generous gaps in between lines of code
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Rivera wrote:When I pass "ArrayList <StudentClass> classes" toString(), I get "0.0, Null, Null" the first time and absolutely nothing the second time.
Any help is greatly appreciated!

Well, the first thing that I see is 9 classes and 669 lines of code, and you've just come up with a pretty basic error.

Have you not tested these classes before now? Individually, and with some dummy data?

If not, THAT'S your basic problem.

However, another major problem I see is that your Student class extends Person, yet doesn't require any of its fields in its constructors. Indeed, it would appear that you can just create a 'new Student()' and then rely on whatever created it to set every field in both the Student AND Person parts.

But, it's not REQUIRED that they do; which, quite apart from being very bad practise, means that right now you can set up a Student with no name, no address, no GPA etc. and your program will happily allow it.

And I strongly suspect that this is exactly what HAS happened.

My advice: StopCoding (←click) and THINK.

Winston
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think your problem is here. Do you see it?

Ask yourself, How are grades and classes getting updated?

Correct the code and post just the main class in a reply.

Nice formatting, BTW.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I just noticed: Welcome to JavaRanch, James! Sorry if I sounded a bit snippy in my previous post, but we do want you to get it right.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!