Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
332
In last 30 days
0
Total given
866
Likes
Total received
7758
Received in last 30 days
89
Total given
628
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

If you have a method calling super.something(...) and doing nothing else, what is the point in writing that method in the first place? Unless you want an example of the usage of super, that is.
4 hours ago
Those values should be input into the constructor. I would think hours worked can be input repeatedly, so that can be a method parameter. The other values should probably be constructor parameters. Otherwise you are permittng your Employee objects to be created in an incoisnstent state.
4 hours ago
I would much prefer to throw an exception than print error messages and still return an incorrect value. I don't think line 8 will ever be reached.
I would also prefer never to see floats again . And nobody seems to have taken the possibility of a NaN being passed into consideration.
This all shows some of the drawbacks of binary floating‑point arithmetic.
15 hours ago
Welcome to the Ranch

Christoph Schreiber wrote:. . . default constructor . . .

I am afraid that isn't quite correct; that calls a no‑arguments construtor in the base class/superclass, and that might not be a default constructor.

Earlier this morning, I wrote:xyz.super.foo()

I haven't tried that sort of code; I don't think it has a “real” use, and I suspect it won't even compile.
15 hours ago
That is because you wrote return 1; If you want the 0 elsewhere you will have to write super.calc(123, 456) (or similar) there. You can only get the result if you use super.calc(...) direcly in an instance method. You cannot use super like that in a static method. If you get xyz.super.foo() to compile, you will get the same as for xyz.foo() because of polymorphism.
18 hours ago
ZZ, please don't edit posts after they have been repleid to; I have reverted the changes.
18 hours ago
Divya Pamulapati,welcome to the Ranch
All employess should have some sort of payment; there should be an abstract getEarnings() method or similar in the Employee class. It can be implemented by all the different subclasses.
1 day ago
Welcome to the Ranch (again).

When were you given that code? It uses a very old‑fashioned style of programming.
Nowadays, one would not call close(), but use try with resources instead. Beware of using hasNextLine() on a text file. Many text files end with a line end character, in which case hasNextLine() returns true, but any attempt to read that next line will fail because the line is empty.The hasNextLine() call will find seven lines in that file, but that shouldn't cause you any difficulties in this particular instance.
1 day ago
Congratulations everybody and thanks to AG for promoting his book.

Kevin O'Sullivan wrote:. . . It returns the enum type depending on which char value is entered,How would you go about writing it?

You mean the enum constant is returned. The method is obviously called on the same object as we are in, and it doesn't take a parameter, so it is not at all clear how it works.
You don't write chars in a text component; you write Strings. If you need a char, you have to use charAt(0) or similar.
I probably wouldn't write such a method at all. I would have a book object with a genre field, and use its getGenre() method. Then you can use toString(). If you write x + y where x is a String and y is a non‑null reference to an object, the + operator causes toString() to be called.
1 day ago
Don't know, but please only say, “class method” to mean a static method.
1 day ago
PK: welcome to the Ranch again.

It isn't quite a FizzBuzz because nested ?:s represent a sort of if‑else and a FizzBuzz usually requires FizzBuzz be printed for No 15. The original code would have got a straight fail from me because of poor indentation.

I presume everybody noticed that my two code suggestions from August were not exactly equivalent to each other. I would disagree that ?:s should never be nested, but they do require extreme care if nested.
1 day ago

Akash bhamri wrote:@Campbell Ritchie that one is solved bro now how can I do this one . . .

Kindly don't call me “bro”.
Please show us the working version.
1 day ago