Exam 1 Answers 1. a. The problem is that the logical and & is used, which means both expressions are evaluated. If A is 0, then the second expression causes a zero divide. To avoid this, use the conditional and &&. b. a==b does not test a and b for equality; it only compares their references. To fix this, add a method equals to the Point class which overrides the default equals method, and use a.equals(b). (You can't just say use a.equals(b) because the default equals doesn't do the right thing either.) Or, more simply, just use a.distance(b) == 0.0 c. The scope of i does not include the last println statement. Move the declaration int i before the for loop. 2. public class Rectangle { protected double x; protected double y; protected double width; protected double height; Rectangle() { x = 0.0; y = 0.0; width = 1.0; height = 1.0; } Rectangle(double x, double y, double width, double height) { this.x = x; this.y = y; this.width = width; this.height = height; } public static double convertToSqIn(double SqFt) { return (144.0 * SqFt); } public double area() { return (width * height); } } b. public class Square extends Rectangle { Square(double x, double y, double side) { super(x, y, side, side); } } 3. a. public Coins(int numberOfCoins) { this.numberOfCoins = numberOfCoins; } b. public int getValue() { return numberOfCoins; } c. public class Dimes extends Coins { Dimes(int numberOfCoins) { super(numberOfCoins); } public int getValue() { return (10 * super.getValue()); } public String description() { return ("There are " + super.getValue() + " dimes worth " + getValue() + " cents."); d. Add package Money; at beginning of Coins and Dimes. Add import Money.*; to classes outside the package.