Campbell Ritchie

+ Follow
since Oct 13, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
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 go back to the beginning of this th‍read, you will find Piet did explain what was wrong. You were so near yet so far and in the meantime you have wandered randomly each step taking you farther from where you want to be.
44 minutes ago
As you have written it, nowhere. The class you wrote looks incorrect to me.

Please go back to the original specification and work out where that class should be. Remember, as Tim H has told you, this is your work not ours.
1 hour ago

Carey Brown wrote:. . . for historical reasons . . .

...because the [] form part of the type name, rather than the variable name. That is why the [] should go early.
1 hour ago

John Ken wrote:. . . i tried various combinations . .  .

That looks like guessing. You can guess 1000000× and some of the guesses will be correct, just from luck. Or you can think about what you are doing, and get it right first time.
Another thing: you have been posting code with apparently nice indentation, but it is hiding errors. Make sure to learn the rules for an indentation convention (you appear to be using Allman) and stick to those rules faithfully. Your class naming is also peculiar to say the least. I would never think that Employee would implement Comparator.
1 hour ago
Why are you declaring a class on line 35? “Illegal start...” usually mean you have code  out of context where it shouldn't be.
1 hour ago
Can you remember what the 51 Java® keywords are?
1 hour ago
Welcome to the Ranch

I wouldn't manipulate Strings like that at all. I would create a class with age, name, and hobbies fields and make its toString() method return what you want.
I would start by finding out how to read the file. I like a Scanner; if you look through its documentation, you will find how to divide Strings into tokens.Find out what lines 1‑2 mean, using these Java™ Tutorials links (1 2) and this constructor and this method. One of those links will tell you why I didn';t write close(). Find out from the Scanner documentation what nextLine() does, and see whether your book says anything different. I think you have good reason to use nextLine() in your exercise.

Once you have all that working, you will know that you can read the text file. Then you can consider the next stage of the task.
NB: \u201c and \u201d are “ ”

[edit] Add “IvanM” to path String. Notice there is a compiler error in my code, but I have not corrected it. I shall let you find it.
2 hours ago
Adding discussion to our testing forum.
6 hours ago

Rob Spoor wrote:. . . if you add a field . . .

If you simply add a field, equals() and hashCode() will still fulfil their general contract, even though you will now have a peculiar definition of equality.See line 5.You can now have two cars with the same make and number but travelling at different speeds and neither equals() nor hashCode() will notice a difference. Strange, but it is a conceivable situation in real life, particularly amongst the criminal classes Your troubles will start if you update equals() or hashCode() but not both; I think updating only hashCode() will break equals() but not vice versa.
Another way to break those methods with an additional field is to add that field in a subclass.Round here, it is legal for taxis to be registered in several boroughs, so the charge can differ on where the fare is picked up. If you use the charge in Taxi#hashCode() only, goodbye general contract for hashCode(). And if you use it in equals(), you have the same problem as Point/ColoredPoint (Joshua Bloch: described in Effective Java, and I think Angelika Langer uses the same example). Goodbye transitivity, and probably goodbye symmetry. Whether a tool will generate such a method, I don't know.
I am sure Rob is correct that generated code will be correct and doesn't need testing. But if such a method is generated in subtypes, then the generated code can be incorrect. If your tool generates an equals() method in Car and in Taxi, even if you remove chargePerMile from the method, you will still have incorrect code because one version will include ...ob instanceof Car... and the other ...ob instanceof Taxi... Goodbye symmetry. Some of the errors you get in handwritten code only can be avoided with @Override. But do any of your tests compare hash codes?
6 hours ago
Please don't ask the same question twice. I have merged the discussions and added them to our JavaScript forum.
Your large font and blue text do nothing for the legibility of the posts. Please avoid them. Also please avoid quoting the whole of the preceding post.
Gourav Das,
I have merged your topic into this topic. I hope that helps.
21 hours ago
I merged your stuff with the following thread. I hope that is okay by you.
21 hours ago
I hope you will be teaching how error‑prone global variables can be.
1 day ago
Yes, that question's wording isn't clear on its own. But the readers are expected to know the definition of equality used by the Collections Framework. That is equal according to Object#equals(Object). By that definition two StringBuilder objects with identical content are not equal because they don't test that feature in the equals() method.