CSC 222: Computer Programming II
Spring 2005

Test 1 Review

Java review class structure: data fields, methods, constructors public static void main parameters vs. data fields vs. local variables data types: primitive (int, double, char, boolean) vs. object control: if, if-else, while, for Scanner class, user input predefined classes: String, array, ArrayList design: highly cohesive, loosely coupled Java interfaces & polymorphism Comparable interface, Collections.sort defining an interface "interface" instead of "class"; list method headers implementing an interface "implements XXX"; must implement all specified methods polymorphism class hierarchies: e.g., Comparable, String, Integer e.g., Grade, LetterGrade, PassFailGrade event handling ActionListener interface, actionPerformed method Timer class, associated ActionListener inner classes hides method-specific classes, can access local variables if final Java event handling events, event sources, event listeners user interaction with buttons JFrame: setSize, setDefaultCloseOperation, add, setVisible JButton: addActionListener text display with labels JLabel: getText, setText organizing the interface JPanel: add user input with text fields & areas JTextField: getText, setText JTextArea: getText, setText, append, setEditable, setLineWrap JScrollPane, JOptionPane layout management: setLayout BorderLayout: NORTH, WEST, CENTER, EAST, SOUTH GridLayout: specify number of rows and columns Recursion recursive algorithms base case(s), recursive case(s) recursive methods: fibonacci, GCD, ... recursive classes: Triangle, PermutationGenerator, ... recursive thinking (think only 1 level deep) 1. make sure it works for base case 2. assume recursive calls work on simpler problems 3. make sure the solutions to simpler problems are combined correctly avoiding infinite recursion must have base case(s), each recursive casr must get closer recursion vs. iteration efficiency tradeoffs, redundancy