Model answers for test 5 Q1: just run the code Q2: part a: abstract class HorizontalScrollbarAdapter extends Scrollbar implements AdjustmentListener { public HorizontalScrollbarAdapter() { super(Scrollbar.HORIZONTAL); addAdjustmentListener(this); } public HorizontalScrollbarAdapter(int v, int s, int min, int max) { super(Scrollbar.HORIZONTAL,v,s,min,max); addAdjustmentListener(this); } public void adjustmentValueChanged(AdjustmentEvent e) { setFromBar(); } abstract public void setFromBar(); } part b: p.add(new HorizontalScrollbarAdapter(0,60,0,300) { public void setFromBar() {sValue = getValue();} }); Q3: // accept whatever CORRECT hash function, // even silly stuff like: public int hashCode() { return 0;} // correctness matters // // THIS IS WRONG: // // public int hashCode() { return super.hashCode();} // // why? public class PointXY { private int x; private int y; public int getX() { return x;} public int getY() { return y;} public PointXY() {x=0;y=0;} public PointXY(int x1, int y1) {x=x1;y=y1;} public int hashCode() { return (17 + x)*43 + y;} public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (getClass() != o.getClass()) return false; PointXY o1 = (PointXY) o; return (x == o1.x) && (y == o1.y); } } import java.awt.*; public class ColorPointXY extends PointXY { private Color color; public Color getColor() { return color;} public void setColor(Color c) { color = c;} public ColorPointXY() {color = Color.red;} public ColorPointXY(Color c) {color = c;} public ColorPointXY(Color c, int x, int y) { super(x,y); color = c; } public int hashCode() { return (23 + super.hashCode())*43 + color.hashCode(); } public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (getClass() != o.getClass()) return false; ColorPointXY o1 = (ColorPointXY) o; return color.equals(o1.color) && super.equals(o1); } }