How would I override toString() in object? I don't know what the toString() in object is anyway. Is it a method that java has in every class, but you just can't see it or something?
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html
I wouldn't try to override it. Can you just make it private method to your class and then use a public getString() method if you need it?
If I make it private, then I can't call it from my main method which is in another class. Public doesn't seem to change anything.
You could just change the name to getString()
That's how I have it at the moment, but my text book specifically asks for toString()
If you make it private, can you call it from your main by using Fan.toString() ?
No, it still gives me the same error in the fan class that it gives me when it's not private. The main method also says that "toString() has private access in Fan"
I'm not impressed with your textbook right now. lol What are you trying to do when calling it anyway?
Just print what the toString() method returns
It just prints this
Fan Speed: 3
Fan Color: yellow
Fan Radius: 10.0
Fan Color: blue
Fan Radius: 5.0
fan is off
And getString() does it fine yea? Does it matter? Do you have like a really cruel professor or something? lol
I don't know if she will knock points off or not. I have always had my programs work properly while following exactly what the book wants until now. I kind of want to figure out how to make the toString() work now though, but I will turn it in as getString() if I can't figure it out by then,
I'd like to test some things out myself but I've gotta get some sleep. If you do decide to go with getString() maybe just leave a comment in your code of the technical reasons why overriding toString doesn't work and try to win her favor by showing you were researching and making an effort? Idk. Just an idea.
Alright, thanks.
Make it public, not static.
Then it won't let me call it from the main method, because it isn't static.
You have to override the parent toString() method in Fan class.
And in the app Main method need a new member or variable from the Fan, also import if it is in different package :)
Also your Fan Class need a better structure, and call status or something like that from toString for re-usability.
Like:
You shouldn't need to call toString() directly, and you really shouldn't be calling it on a class. I can't gather much from the amount of code you've shown, but you're probably supposed to be creating an instance of the Fan class in your main method.
Ohh one more thing :)
You also can use method overloading, get/set prefix is just a convention, this way your code much more prettier :)
I separate the dynamic variables into a FanState object, so you can use this for every fan, or child fan (Gpu Cpu, Case, etc. )
yeah... don't name your things the same as built in things.