my Dear vivek your intime:9.23 outtime13.45 work hour:4.219999999999999 my Dear jayesh your intime:9.45 outtime13.45 work hour:4.0
Joined: Apr 26, 2005
name.toString() instead of this.toString();
Maybe that will help.
SCJP 5.0<br />SCWCD
Joined: Apr 26, 2005
Instead of using toString() you can create Getters in your Nameof_emp class.
Then in your Employee class you will access the first, middle and last name by using:
name.getFirst_n() and so on.
I hope that helps.
Joined: Aug 07, 2003
Following on Henrik's idea, I'd also create some helper methods for the Nameof_emp class like getFullName() [all three concatenated together with spaces as necessary) and getFirstAndLastName() [should be obvious]. This will make it easier to enforce uniformity of how names are built.
For example, if you code getFullName() like this:you'll get "null" showing up when a portion of the name is not specified. When fixing that, make sure you don't return two spaced between a first and last name when the middle name is null.
Finally, it will make debugging and writing logging code easier if you provide a toString() method for the Nameof_emp class. Just call one of the other methods -- probably getFullName(). Normal code shouldn't rely on toString() since none of the various forms for a three-part name can really be viewed as "correct." In my code I tend to use toString() only when displaying an object for developers, thus my choice of the full name to ease debugging.
Now for some stylistic advice. I recommend reading and following the Java naming conventions. Classes use InitialUpperCamelCase, methods and non-final variables use initialLowerCamelCase, and final variables (constants) use ALL_CAPS_WITH_UNDERSCORES. By following these conventions you make it easier for other people to quickly understand your code.
How about FullName or PersonName instead of Nameof_emp? A three-part name isn't inherently limited to employees, and thus the class name shouldn't imply such a limitation. It's fields would be firstName, middleName, and lastName with methods like I've used above.