There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:did you override the toString method for your newrunner class? I'd bet not...so Java doesn't know how to print your objects.
Tony Docherty wrote:Can I suggest you read this page of the Java tutorial http://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html
Donald Bough wrote:I'm not familiar with overriding String methods, so that's a no. What can i do to fix this?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Donald Bough wrote: I'm not familiar (bear with me) with how to build the the many different strings that I want to be printed out in my toString method though.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:
Donald Bough wrote: I'm not familiar (bear with me) with how to build the the many different strings that I want to be printed out in my toString method though.
Well..the first step when writing ANY program is to forget about programming.
What do you WANT your code to print out? I don't know anything about your runner class. but tell me, in plain old English, what you want to see when you run this line:
System.out.println(amountofrunners.get(i));
Assume that particular runner has:
datafirstname = fred
datalastname = rosenberger
datagrade = A+
dataschool = Hard Knocks
dataorigtime = 12:00 noon
or feel free to use any other data set, but explain in detail what you would expect or want to see.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:ok...slow down.
There is a difference between printing out an arrayList, and printing out an object that is IN your arrayList. Work on one thing at a time. write some test code that creates a single runner, and prints it. Once you know you can print a single runner object, THEN figure out how to print each one in the arrayList.
The secret/most important thing to learn is to code VERY SMALL pieces at a time. I usually only write at most 3 lines of code before I re-compile and test test test test test.
fred rosenberger wrote:ok...slow down.
There is a difference between printing out an arrayList, and printing out an object that is IN your arrayList. Work on one thing at a time. write some test code that creates a single runner, and prints it. Once you know you can print a single runner object, THEN figure out how to print each one in the arrayList.
The secret/most important thing to learn is to code VERY SMALL pieces at a time. I usually only write at most 3 lines of code before I re-compile and test test test test test.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:did you define the getFirstname method (and the others?) Do those methods work? How do you know?
Don't get me started about those stupid light bulbs. |