announcements & review course on-line survey due tuesday 10pm on eblackboard exam wednesday 12/7...

19
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 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

Upload: jacob-henry

Post on 06-Jan-2018

215 views

Category:

Documents


1 download

DESCRIPTION

Topics you understand for loops while loops I/O conditionals classes, objects, methods, instance variables arrays File input Image manipulation Sorting Recursion GUI

TRANSCRIPT

Page 1: 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

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

Page 2: 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

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

Page 3: 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

Topics you understand

• for loops• while loops• I/O• conditionals• classes, objects, methods, instance variables• arrays--------------------------------------------------------• File input• Image manipulation• Sorting• Recursion• GUI

Page 4: 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

File Input• use Scanner class• same methods used with terminal

– nextInt()– next()– hasNextInt()

Page 5: 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

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()

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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];

}}

}

Page 10: 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

MergeSort AlgorithmMergeSort(array) {

MergeSort(first half); MergeSort(second half); Merge first and second;}

Page 11: 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

QuickSort AlgorithmQuickSort(array) {

choose pivot; partition array; //small to left, big to right QuickSort(left); QuickSort(right);}

Page 12: 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

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

Page 13: 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

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)

Page 14: 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

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)

Page 15: 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

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,

Page 16: 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

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

Page 17: 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

LayoutManager• public interface LayoutManager

– Defines the interface for classes that know how to lay out Containers.

– e.g. BorderLayout, FlowLayout, GridLayout

Page 18: 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

Big Picture

Container(JFrame)

Container(JPanel)

Container(JPanel)

Container(JPanel)LayoutManager

Components

Components

Components

Page 19: 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

Thank you!