Question1: 2 3 2 10 Question2a: public static double measure(double[] a) { double sum = 0; for (int i = 0; i < a.length; i++) { sum += a[i] * a[i]; } return Math.sqrt(sum); } Question2b: public static double[] sum(double[] a, double[] b) { double[] c = new double[a.length]; for (int i = 0; i < c.length; i++) { c[i] = a[i] + b[i]; } return c; } Question2c: public static void main(String[] args) { double[] a = new double[] {1,3}; double[] b = new double[] {5,4}; System.out.println(measure(sum(a,b))); } Question3: public class SimpleScheduler { private double totalHours; public SimpleScheduler() { totalHours = 0; } public void addProject(String name, double hours) { totalHours += hours; } public double workTime() { return totalHours; } public double overTime() { if (totalHours <= 8) return 0; return totalHours - 8; } } Question 4: public class TicTacToeModel { private Cell[][] matrix; public TicTacToeModel() { matrix = new Cell[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { matrix[i][j] = Cell.FREE; } } } public Cell getCell(int i, int j) { return matrix[i][j]; } public Cell setCell(int i, int j, Cell c) { matrix[i][j] = c; } public boolean isWinning() { for (int i = 0; i < 3; i++) { if (matrix[i][1] != Cell.FREE && matrix[i][0] == matrix[i][1] && matrix[i][1] == matrix[i][2]) return true; if (matrix[1][i] != Cell.FREE && matrix[0][i] == matrix[1][i] && matrix[1][i] == matrix[2][i]) return true; } if (matrix[1][1] != Cell.FREE && matrix[0][0] == matrix[1][1] && matrix[1][1] == matrix[2][2]) return true; if (matrix[1][1] != Cell.FREE && matrix[0][2] == matrix[1][1] && matrix[1][1] == matrix[2][0]) return true; return false; } public boolean isFree() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (matrix[i][j] == Cell.FREE) return false; } } return true; } } Question 5: public static void walk(Oracle oracle) { int x = 0; int y = 0; for (;;) { switch (oracle.guide()) { case LEFT: x--; break; case RIGHT: x++; break; case UP: y++; break; case DOWN: y--; break; case STOP: System.out.println("("+x+","+y+")"); return; } } } public class TestOracle implements Oracle { private int i; private static final Guide[] steps = {LEFT, LEFT, UP, RIGHT, STOP}; public TestOracle() { i = 0; } public Guide guide() { return steps[i++]; } }