Upload
annice-black
View
217
Download
0
Embed Size (px)
Citation preview
CS 151: Object-Oriented Design December 5 Class Meeting
Department of Computer ScienceSan Jose State University
Fall 2013Instructor: Ron Mak
www.cs.sjsu.edu/~mak
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
2
Animation Example: Merge Sort
Animate the merge sort algorithm.
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
3
Animation Example: Merge Sort, cont’d
Two threads The main thread for the GUI. The sorting thread.
Class Sorter implements the Runnable interface.
Method MergeSort.sort() takes two parameters: The Double array to be sorted A Comparator<Double> object
Method compare() returns -1, 0, or +1 depending on whether object1 is less than, equal to, or greater than object2._
interface Comparator<T>{ int compare(T object1, T object2);}
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
4
Animation Example: Merge Sort, cont’d
The run() method of class Sorter:public void run() { MergeSorter.sort(values, new Comparator<Double>() { public int compare(Double d1, Double d2) { panel.setValues(values, d1, d2); try { Thread.sleep(DELAY); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } return d1.compareTo(d2); } }); panel.setValues(values, null, null);}
Update the displaybefore each compare.
Sleep
Then compare
Demo
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
5
Animation Challenge
Spawn (create and start) a thread for each merge. Do the merges in parallel! Will the sort be faster or slower?
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
6
Unofficial Field Trip
Computer History Museum in Mt. View http://www.computerhistory.org/
Saturday, December 7, 11:30 – closing time
Special free admission. Schedule
11:30-12:00 – PDP-1 plays Christmas carols 11:45-1:00 – Live demonstration of the IBM 1401 1:00-1:30 – Live demonstration of the Babbage Difference
Engine 1:30-closing – Self-guided tours of the Revolution exhibits 3:00-3:30 – Spacewar! demo on the PDP-1 by one of its
authors Extra credit – A multiple-choice quiz based on
the Revolution exhibits The quiz will be distributed before you arrive at the museum. Please enter your answers into Canvas.
} threegroups
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
7
Unofficial Field Trip, cont’d Babbage Difference Engine,
fully operational Hand-cranked mechanical
computer. Computed polynomial
functions. Designed by Charles Babbage
in the early to mid 1800s. Arguably the world’s first
computer scientist, lived 1791-1871.
He wasn’t able to build it because he lost his funding.
Live demo at 1:00 PM His plans survived and this
working model was built. Includes a working printer!http://www.computerhistory.org/babbage/
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
8
Unofficial Field Trip, cont’d
The new Revolution exhibit is now open! Walk through a timeline of the
First 2000 Years of Computing History. Historic computer systems, data processing equipment,
and other artifacts. Small theater presentations.
Atanasoff-Berry Computer
HollerithCensus
Machine
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
9
What was the PDP-1?
Commercial computer produced in 1959 by the Digital Equipment Corporation (DEC).
18-bit word size 4K words of memory
Upgradable to 64K
2700 transistors 3000 diodes Paper tape CRT displaySteve Russell, who programmed the original
Spacewar! video game while at MIT in 1961.
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
10
What was the IBM 1401? IBM 1401 computer, fully restored and operational
A small transistor-based mainframe computer. Extremely popular with small businesses in the late 1950s
through the mid 1960s Maximum of 16K bytes of memory. 800 card/minute card reader (wire brushes). 600 line/minute line printer (impact). 6 magnetic tape drives, no disk drives.
1402 Card Reader Punch 1407 Console 1401 CPU 729 Tape Drives 1403 Line Printer
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
11
What was Computing Like Before the 1401?
Data was stored in punched cards called “IBM cards” or “Hollerith cards” Named after
Herman Hollerith.
80 columns per card, one character per column. Up to 12 punched holes
per column.
Alphanumeric data, often grouped into fields._
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
12
Data Processing
Data processing was all about punched cards.
My school compiler project: 3½ boxes of punched cards Each box = 2000 cards, 10 lbs.
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
13
Data Processing
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
14
Data Processing
Cards were punched manually at a keypunch machine.
Or they were punched automatically by unit-record equipment under program control._
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
15
The 1403 Line Printer
Each print line can contain up to 132 characters. Mechanically (impact)
printed. No lasers!
Outstanding print quality. Horizontally straight lines
of text.
How fast was the 1403 line printer? 600 lines per minute!
Sample print quality.
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
16
The 1403 Print Mechanism 132 horizontal print hammers
behind the paper, one per print column. Paper pulled upwards.
Inked ribbon in front of the paper.
Horizontally rotating print chain in front of the ribbon. The print chain contains type slugs
of the characters.
As the desired character flies past a print column, the column's hammer fires to press the paper against the ribbon and the type slug. The print chain does not stop. The paper advances as soon as the
entire line is printed.
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
17
1402 Card Read Punch
Stack of punched cardsto be read
Card hoppers
Blank cardsto be punched
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
18
How the 1402 Read Punched Cards (cont’d)
It’s all in the timing! One brush per card column. All 80 columns were read simultaneously. Cards were fed into the 1402 card hopper
“9 edge face down”.
How fast was the 1402 card reader? Up to 800 cards per minute!
_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
19
IBM 729 Magnetic Tape Drive
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
20
Postmortem Reports
Due Monday, December 9 at 11:59 PM A few paragraphs.
Word document or just an email message Individual and private.
What did you learn in this class?
What were your accomplishments on your project team?
How well did each of your teammates do?_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
21
Final Exam
Thursday, December 12 in Science 311 7:15 – 9:30 AM
It will be similar to the midterm. Covers the entire semester.
_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
22
Review for the Final Exam
Are you a better programmer today than you were at the start of the semester?
What makes you a better programmer? It’s more than just writing programs that work.
Although that’s important! Requirements
Functional Non-functional
Documentation UML diagrams Use cases CRC cards
Good design Reliable Robust Flexible Maintainable
_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
23
Review for the Final Exam, cont’d
How do the following make you a better programmer?
Loose coupling Encapsulation Coherency Consistency Programming to the interface Design patterns
factory, strategy, iterator, observer, composite, decorator, template
Dynamic class loading_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
24
Review for the Final Exam, cont’d
Understand how each of the following contributes to better design:
Frameworks Generic types Interfaces Inheritance Polymorphism Abstract classes Type inquiry Reflection Metadata descriptor classes
_
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
25
Review for the Final Exam, cont’d
Design patterns Know when to use when designing a program. Recognize their use when reading a program.
Graphical User Interface (GUI) programming with Swing Event handlers Frames, panels, buttons, text fields, menus, etc. Layout managers Inversion of control
Collections framework Interfaces Classes Ability to create your own collection class
SJSU Dept. of Computer ScienceFall 2013: December 5
CS 151: Object-Oriented Design© R. Mak
26
Review for the Final Exam, cont’d
Multithreading
The Runnable interface The run() method Synchronization
race conditions locks lock conditions synchronized methods
Thread-safe code
Your Rock-Paper-Scissors project._