190 likes | 276 Views
Course on-line survey due Tuesday 10pm on eBlackboard Exam Wednesday 12/7 ACES 2.302 5:30--7:30 Tournament cancelled Discussion section grades drop first 5 or average out. Topics to review: background for, while, if/else, … read from file array of objects
E N D
Course on-line survey due Tuesday 10pm on eBlackboard Exam Wednesday 12/7 ACES 2.302 5:30--7:30 Tournament cancelled Discussion section grades drop first 5 or average out Topics to review: background for, while, if/else, … read from file array of objects two dimensional arrays Color sorting bubble, quick, merge recursion GUI Announcements & Review
Basic Exam Format Open book, open notes - No computers or cell phones - I suggest you print out your programming assignment solutions and/or my in class examples 5 questions: • 4 short answer, similar to previous exam • object allocation • I/O and efficient representation & computation • Image manipulation • Class design
Topics you understand • for loops • while loops • I/O • conditionals • classes, objects, methods, instance variables • arrays -------------------------------------------------------- • File input • Image manipulation • Sorting • Recursion • GUI
File Input • use Scanner class • same methods used with terminal • nextInt() • next() • hasNextInt()
Image Manipulation • int[][] myPixels • height = myPixels.length • width = myPixels[0].length • int -> Color • myColor = new Color(myPixels[i][j]); • Color -> int • myPixels[i][j] = myColor.getRGB(); • Color manipulation • Color black = new Color(0,0,0); • int red = myColor.getRed(); • getGreen(), getBlue()
Sorting - BubbleSort • one element at a time • moving 7+6+5+4+3+2 = 27 times
Sorting - MergeSort • divide by half and sort each half • moving (1+1+1+1) + (2+2) + (4) = 12 times
Sorting - QuickSort • left < pivot < right • moving 7+ (3+2) + 1 = 13 times
BubbleSort Algorithm for (int i=0; i<array.length; i++) { for (int j=0; j<array.length-i ; j++) { if (array[i]>array[j]) { swap array[i] and array[j]; } } }
MergeSort Algorithm MergeSort(array) { MergeSort(first half); MergeSort(second half); Merge first and second; }
QuickSort Algorithm QuickSort(array) { choose pivot; partition array; //small to left, big to right QuickSort(left); QuickSort(right); }
Recursion • Repetition with a smaller problem size • organism marking • merge sort, quick sort • tower of hanoi • How to use • Call the method in itself, with different parameter
Remember where PC was hanoi(3, src, aux, dst) hanoi(2, src, dst, aux) hanoi(2, aux, src, dst) hanoi(2, src, dst, aux) hanoi(1, src, aux, dst) hanoi(1, aux, dst, src) hanoi(2, aux, src, dst) hanoi(1, dst, src, aux) hanoi(1, src, aux, dst) • First-In Last-Out
Recursion as Stack • First-In Last-Out
Graphical User Interface • Components, Containers, Layouts • Components • an object having a graphical representation that can be displayed on the screen and that can interact with the user. • e.g. Canvas, JButton, JLabel, JRadioButton, JTextField, JSlider,
Container • Container • public class Container extends Component • A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT components. • Components added to a container are tracked in a list. • e.g. JFrame, JPanel
LayoutManager • public interface LayoutManager • Defines the interface for classes that know how to lay out Containers. • e.g. BorderLayout, FlowLayout, GridLayout
Big Picture Container(JPanel) Container(JPanel) Container(JPanel) Container(JFrame) LayoutManager Components Components Components