announcements & review course on-line survey due tuesday 10pm on eblackboard exam wednesday 12/7...
DESCRIPTION
Topics you understand for loops while loops I/O conditionals classes, objects, methods, instance variables arrays File input Image manipulation Sorting Recursion GUITRANSCRIPT
Announcements & Review
Course on-line survey due Tuesday 10pm on eBlackboard
Exam Wednesday 12/7 ACES 2.302 5:30--7:30
Tournament cancelled
Discussion section gradesdrop first 5 oraverage 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
Basic Exam FormatOpen book, open notes
- No computers or cell phones- I suggest you print out your programming
assignment solutions and/or my in class examples5 questions:
1. 4 short answer, similar to previous exam2. object allocation3. I/O and efficient representation & computation4. Image manipulation5. 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
8 7 6 5 4 3 2 17 8 6 5 4 3 2 17 6 8 5 4 3 2 17 6 5 8 4 3 2 17 6 5 4 8 3 2 17 6 5 4 3 8 2 17 6 5 4 3 2 8 17 6 5 4 3 2 1 8
Sorting - MergeSort• divide by half and sort each half• moving (1+1+1+1) + (2+2) + (4) = 12
times8 7 6 5 4 3 2 18 7 6 5 4 3 2 18 7 6 5 4 3 2 17 8 5 6 3 4 1 25 6 7 8 1 2 3 41 2 3 4 5 6 7 8
Sorting - QuickSort• left < pivot < right• moving 7+ (3+2) + 1 = 13 times
8 7 6 5 4 3 2 14 3 2 1 5 8 7 62 1 3 4 5 6 7 81 2 3 4 5 6 7 8
BubbleSort Algorithmfor (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 AlgorithmMergeSort(array) {
MergeSort(first half); MergeSort(second half); Merge first and second;}
QuickSort AlgorithmQuickSort(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
• First-In Last-Outhanoi(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, dst, src, aux)
hanoi(2, aux, src, dst)
hanoi(1, aux, dst, src)hanoi(1, src, aux, dst)
Recursion as Stack
hanoi(1, src, aux, dst)hanoi(2, src, dst, aux)hanoi(3, src, aux, dst)
•First-In Last-Out
hanoi(1, aux, dst, src)hanoi(2, aux, src, dst)hanoi(3, src, aux, dst)
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(JFrame)
Container(JPanel)
Container(JPanel)
Container(JPanel)LayoutManager
Components
Components
Components
Thank you!