Cruz Loyde wrote:. . . Prof gave sets of instructions on how to do the methods so i really cant do my own thing.
I never like to see assignments specified in such detail. I think that is over‑specification and it prevents you using what may be better solutions like Carey's boolean return type or my suggestion of returning an unmodifiable List.
posted 2 weeks ago
Piet Souris wrote:. . . the singular form of media is medium . . .
If you will live somewhere like Holland where they speak better English than in England
What I was taught is that you use an exception only to catch processing that is exceptional. That is, when you are not expecting the condition to happen, but you're protecting against it. Another way to think of it is you throw an exception when there is no good way to recover from the condition.
You don't want to use an exception to signal the success or failure of a process, because these are normal conditions in the method. You might want to throw an exception when null is passed because this is often a sign that something has gone wrong with the calling code, but I could also see returning failure (false) in this case too.
All things are lawful, but not all things are profitable.
I might have missed this in the thread, but if the List<Media> is not supposed to have duplicates, then isn't that a Set?
You can then skip the whole checking thing in the addMedia method, so long as equals has been correctly defined.
posted 1 week ago
Dave Tolls wrote:. . . isn't that a Set? . . .
Of course it is, but I htink OP has been told not to use Sets (not certain). More precisely it would be a set orderd by insertion order, like a linked hash set.
Judging from OP's replies, he's still a ways off from being able to implement equals() that would work for this problem. This exercise might lead up to that though. He just needs to figure out what "duplicate" means. So far, he hasn't been able to articulate that concept very well so naturally, he's having difficulty coding it.
Edit: I take that back. Missed his last post with the code that actually does what he needed to do.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck