I just beginning learn object oriented programming and I've developed this class and works well, but the last method flag this suggestion "Add@Override Annotation"
can anyone tell me why???
further, I'd be grateful if you give me any advices about this class
Thanks in advance
I Hear I Forget, I See I Remember, I Do I Understand.
I'm just learning java too.. as far as I know this is because your method has the signature toString which means you are overriding the toString method of the object class which is the implicit superclass of all other classes. So this is just a suggestion for you to add the annontation to you code to say your are overriding a method of the superclass.
Annotations. This one isn't required, but it's a good practice to always use the @Override annotation. That prevents you from making typos:
Since the method name is hashCode, with capital C, this is not overriding so there will be a compiler error.
The fan speed is set by an integer and you have defined 3 constants for the speed settings. However it's perfectly legal to call it with: fan.setSpeed(5000); (if 3 is fast then how fast would 5000 be ). A better way would be to define an enum.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
And it might be a good idea to make the final fields public. Then other classes can invoke them to set the fan's speed.
As an atlernative, you can set bounds and refuse to alter the speed if it is outwith the permitted speed range (in your case 0-3 inclusive, using 0 as "stop"). Wouter's suggestion of an nenum is far better, however.