There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
When all you have is a hammer, everything looks like a thumb.
Jeff Verdegan wrote:You could make printAtlantic static. That would get rid of one compilation error. But that's just a non-OO hack. I hope you will not choose to continue down that path.
Justin Johnson wrote:I tried that and get a different error
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method printAtlantic() from the type LeagueStats
Gary Deer wrote:
To keep the design the way it is I would suggest using an array, adding the division as a member variable, and using a for loop to iterate over the teams printing those whose division variable == "Atlantic". I'm just going off the top of my head here, so there might be scoping issues with that solution too, but you might think of something else while trying to implement that.
Justin Johnson wrote:(The specs)...are set in stone and will always be held constant for the scope of this program. I just want a small program to mess around with stats a little, this isn't something I'm looking to have for years.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan wrote:
I think it's time to take a step back and actually learn and understand the concepts of static and non-static, so you'll be able to use them appropriately in your design.
Justin Johnson wrote:
In the meantime though, if there is a quick fix available for my program above what is it?
So far I've posted all my code and none of the suggestions given so far have worked. Are they working for anyone else?
Jeff Verdegan wrote:
Justin Johnson wrote:
In the meantime though, if there is a quick fix available for my program above what is it?
There almost certainly is. I'm sure not gonna give it out though. I don't like encouraging bad habits.
So far I've posted all my code and none of the suggestions given so far have worked. Are they working for anyone else?
If they didn't work, then you didn't follow them correctly. If you show your current code (or better a version stripped down to an SSCCE), then somebody should be able to point out where you went wrong.
Justin Johnson wrote:Yeah I followed a lot of variations of the quick fix advice given (starting with simply adding the static modifier to printAtlantic() )and it still doesn't work, but you're right, getting back to the basics is the way to go. I appreciate your help and thanks for trying.
LeagueStats.java:10: non-static variable Penguins cannot be referenced from a static context
Penguins.printTeamStats();
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
When all you have is a hammer, everything looks like a thumb.
Gary Deer wrote:
Since the ID is automatically generated by the code it's static because the computer already knows at compile time what the value of this variable will be at any moment since it's just (1...n+).
However, if you initialize sally then at least the computer knows about her.
This is done by just typing Student Sally; outside of main(). (Now Sally is on the stack somewhere; an object is born)
not the most elegant solution, but at least the computer will trust you when it sees you've hard coded the print method with the object.
Jeff Verdegan wrote: "This really doesn't mean anything at all and should be ignored."
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:@quote=Jeff Verdegan - "This really doesn't mean anything at all and should be ignored."
Seems to me we're arguing semantics, and not Justin's intention, which is (as I understand it) to collect hockey stats.
They worked all right when I went back to your post and tried them.Winston Gutkowski wrote: . . . Sorry guys, for some reason, the '[quote]' brackets aren't working.
Campbell Ritchie wrote:
They worked all right when I went back to your post and tried them.Winston Gutkowski wrote: . . . Sorry guys, for some reason, the '[quote]' brackets aren't working.
I hope I haven’t trodden on your toes by editing your tags; if I have, then I am sorry.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
When all you have is a hammer, everything looks like a thumb.
money grubbing section goes here:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|