Donald Bough

Greenhorn
+ Follow
since Dec 09, 2013
Donald likes ...
Eclipse IDE Chrome Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Donald Bough

fred rosenberger wrote:did you define the getFirstname method (and the others?) Do those methods work? How do you know?



I had one of my friends who is a computer science student check it out (I'm just a Junior in highschool) and he figured out that I was actually using my scanner that was reading the text file in a method before readfile, so it couldn'tread the text file again with the while loop. Also, he put everything in a list, then after the while loop, he put that list into an array. Thank you for all the help that you have given me on this project so far. I've found this forum to be the most responsive of the different Java forums, thanks!
10 years ago

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.



Also, I tried printing out my datafirstname, datalastname... directly in the while loop with a system out and NOTHING PRINTED. Maybe there is a bigger problem?
10 years ago

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.



Alright, I'm still having troubles with printing off my object references. Maybe it was with how I setup my runner class?

Then, in my while loop I just tried to print out my newrunner object right after creating it, but there's still nothing showing up in the console.
10 years ago

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.



That's a really unique way of thinking about it, I like it! Whenever I print out my arraylist of runners (amountofrunners),
I want to see something along the lines of:
Jackson Bertoli 11 Jasper 15.29
Jarit Perkins 10 Jasper 15.37
Riley Stohler 12 Southridge 15.39
firstname, lastname, grade, school, time.

If I could do this, that I means I have all of my runners' information properly stored together and I can do my calculations properly later on!

10 years ago
OK EXCELLENT. Nobody ever explained that I'm making new references to the same object with this while loop. That makes much much more sense. 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.
10 years ago

Tony Docherty wrote:Can I suggest you read this page of the Java tutorial http://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html



So the problem was with printing off my objects, not that my objects all had the same name? Instead of


I should have



And I'm sorry, but you still haven't answered how to distinguish among objects with the same names but that holding different data.
10 years ago

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.



I'm not familiar with overriding String methods, so that's a no. What can i do to fix this?
10 years ago
I'm working on a program that will eventually allow me to change individual race results in a text file to see how it would've changed the team placing in a race. For now, I ran into a problem. First, I'm reading all the different information from a text file that is formatted as place, first name, last name, grade, school, and time. Here is what one line looks like

1 Jackson Bertoli 11 Jasper 15.29

In my code, I am taking each one of these elements, except for place because I need to generate that myself later on, and storing it in a "runner" object in order to keep each runner's information together. The problem I'm having is that I'm reading through my text file with a while loop, and I need to create a new object every time for every new line of information. I have managed to do this, but now I am stuck with many different "newrunner" objects that are all named the same and I have no clue how to distinguish between one newrunner object and another. Here's the code



So as you can see, I have a class runner, that uses runner objects with the firstname,lastname.... setup and then I am putting all of my "runner" objects in an arraylist called "amountofrunners". I am able to make the many different runner objects, but when I tried to print them out with the code



But would get something along the lines of

newrunner@32414ja
newrunner@ij123451
newrunner@25ia0d12
newrunner@1r31456

for however many runner objects I had made.
Thanks in advance for the help
10 years ago