public boolean equals( Object o )
{
return compareTo( (Item)o ) == 0;
}
{
return compareTo( (Item)o ) == 0;
}
Strictly speaking, by overriding the equals method in this way we are violating the general contract for equals, which is required never to throw an exception. The usual way to avoid this uses theinstanceof operator (which is not part of the Advanced Placement Java subset):
public boolean equals( Object o )
{
return ( o instanceof Item ) &&
( compareTo( (Item)o ) == 0 );
}
{
return ( o instanceof Item ) &&
( compareTo( (Item)o ) == 0 );
}
EIMACS:
- I don't like this because you would never, ever want to use the first implementation of equals. Even though they make a note of this, it shows that the philosophy for their curriculum is out of touch with reality.
- Since the AB exam is no longer a thing, eimacs really needs to update their curriculum to stop focusing on the Collegeboard's curriculum. Operators like instanceof are important in Java, and acting like they don't exist is just plain stupid. I wish they would just teach instanceof once so they don't have to make a special case every time instanceof is necessary for solving a problem.
- Learned more about binary search, and wrote my own, which was kind of tough because I knew roughly what it should look like but forgot what the midpoint should be set to on each iteration.
- I had mid = (high - low) / 2, when it should actually be low + (high - low) / 2, or (high + low) / 2
- Learned that a binary search runs in O( log2n )
Stop whining! ;-) Actually, it is great to see you have the confidence to put forth a critique like this, but I would rather hear your critique on the whole college board AP process, and the approach it uses to teaching a topic like first year CS, rather than directing your criticism at the eIMACS folks, who are just playing a game they did not design.
ReplyDeleteAs you probably know, I'm an advocate of problem based learning (http://en.wikipedia.org/wiki/Problem-based_learning). In a "real world" problem for which you had chosen Java as to tool, you would never limit learning in the way the curriculum does here. When the goal (and the evaluation process) are centered around passing a test, however, this is the kind of thing that happens.
My recommendation is to use eIMACS for what it is good for, and understand its limitations. If I felt it was not an aide to learning, I wouldn't use it at all, but I don't feel that way. Since you show repeatedly that you are someone with an intrinsic motivation to learn, I won't insist that you continue using it. We could substitute blog posts summarizing readings on the required topics from other resources (like the text book we have in class), together with your investigation of high school programming contest problems like the one you did in your last post.
Learning is the goal, and there are certainly many paths to get there.