1. a) private static int sumOfFactors(int n) { int sum = 0; for (int i = 1; i < n; i++) { if (n % i == 0) { sum += i; } } return sum; } 1. b) private static boolean isPerfect(int n) { return (n == sumOfFactors(n)); } 1. c) public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Please enter a positive integer"); int n = scanner.nextInt(); for (int i = 1; i <= n; i++) { if (isPerfect(i)) { System.out.println(i); } } } 1. d) public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Please enter a positive integer"); int n = scanner.nextInt(); for (int i = 1; i <= n; i++) { if (isPerfect(i)) { System.out.printf("%d = 1", i); for (int j = 2; j < i; j++) { if (i % j == 0) { System.out.printf(" + %d", j); } } System.out.println(); } } } 2. public class TableTennis { private String playerOneName; private String playerTwoName; private int playerOneScore; private int playerTwoScore; private boolean deuce; public TableTennis(String playerOneName, String playerTwoName) { this.playerOneName = playerOneName; this.playerTwoName = playerTwoName; this.playerOneScore = 0; this.playerTwoScore = 0; this.deuce = false; } public String getPlayerOneName() { return this.playerOneName; } public String getPlayerTwoName() { return this.playerTwoName; } public int getPlayerOneScore() { return this.playerOneScore; } public int getPlayerTwoScore() { return this.playerTwoScore; } public void scoreOne() { this.playerOneScore++; if (this.playerOneScore == 10 && this.playerTwoScore == 10) { this.deuce = true; } } public void scoreTwo() { this.playerTwoScore++; if (this.playerOneScore == 10 && this.playerTwoScore == 10) { this.deuce = true; } } @Override public String toString() { return String.format("%s: %2d %s: %2d", this.playerOneName, this.playerOneScore, this.playerTwoName, this.playerTwoScore); } public int winner() { if (!this.deuce && this.playerOneScore > 10) { return 1; } if (!this.deuce && this.playerTwoScore > 10) { return 2; } if (this.deuce && this.playerOneScore >= this.playerTwoScore + 2) { return 1; } if (this.deuce && this.playerTwoScore >= this.playerOneScore + 2) { return 2; } return 0; } } 3. Change the midPoint method to: public Point midPoint(Point p) { double x = (this.x + p.x) / 2; double y = (this.y + p.y) / 2; return new Point(x, y); } 4. A slow solution: public int missingElement(int[] a) { for (int i = 1; i <= 100; i++) { if (isMissing(a, i)) { return i; } } } private boolean isMissing(int[] a, int i) { for (int j : a) { if (j == i) { return false; } } return true; } A fast solution: public int missingElement(int[] a) { int sum = 0; for (int j : a) { sum += j; } return 5050 - sum; }