import java.io.PrintStream; import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.TreeMap; import cse1020.shape.*; public class TestC { public static void main(String[] args) { Scanner input = new Scanner(System.in); PrintStream output = System.out; // Part 1: 3 marks // 1 mark for both prompts // 1 mark for reading name // 1 mark for reading number output.print("Name of this drawing: "); String drawingName = input.nextLine().trim().toUpperCase(); output.print("How many shapes? "); int n = input.nextInt(); // Part 2: 3 marks // 1 mark for list // 1 mark for loop // 1 mark for add List shapes = new ArrayList(); for (int i = 0; i < n; i++) { output.print("*"); shapes.add(ShapeFactory.getRandom()); } output.println(); // Part 3: 9 marks // 1 mark for creating a Map // 1 mark for ShapeFactory.makeMap(shapes) // 1 mark for printing drawing name // 1 mark for loop over keys // 1 mark for Circle case (should use instanceof) // 1 mark for Square case (should use instanceof) // 1 mark for all other shapes // 1 mark for catch // 1 mark for printing "Too many shapes in the drawing!" in catch block try { Map namedShapes = new TreeMap(ShapeFactory.makeMap(shapes)); output.println("Shapes in " + drawingName); for (String name : namedShapes.keySet()) { output.print(name + " is a "); Shape s = namedShapes.get(name); if (s instanceof Circle) { Circle c = (Circle) s; output.println("circle with radius " + c.getRadius()); } else if (s instanceof Square) { Square q = (Square) s; output.println("square with length " + q.getLength()); } else { output.println(s); } } } catch (IllegalArgumentException e) { output.println("Too many shapes in the drawing!"); } } }