20
CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 [email protected] Office Hours 9:00-11:30 am MWF

Overview of Course

  • Upload
    cardea

  • View
    26

  • Download
    0

Embed Size (px)

DESCRIPTION

CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall 864-656-5855 [email protected] Office Hours 9:00-11:30 am MWF. Overview of Course. Construction and Use of Objects Definition Methods Use Data Structures Definition and Use Algorithm Analysis. - PowerPoint PPT Presentation

Citation preview

Page 1: Overview of Course

CPSC 102: Computer Science II

Dr. Roy P. Pargas

408 Edwards Hall864-656-5855

[email protected]

Office Hours9:00-11:30 am MWF

Page 2: Overview of Course

Overview of Course

• Construction and Use of Objects– Definition– Methods– Use

• Data Structures– Definition and Use

• Algorithm Analysis

Page 3: Overview of Course

Semester Outline

• 1. The Object-Oriented Method (3)

• 2. Comments, Conditions, and Assertions (1)

• 3. Vectors (3)• 4. Design Fundamentals(3)• 5. Sorting (3)

• Test 1

• 6. Lists (2)• 7. Linear Structures (3)• 8. Iterators (2)• 9. Ordered Structures (3)• 10. Trees (3)

• Test 2• 11. Priority Queues (3)• 12. Search Trees (3)• 13. Dictionaries (3)• 14. Graphs (4)

• Test 3

Page 4: Overview of Course

Objects

• Classes– templates for objects

• Instances or Objects– constructed from

classes

• Message passing– usually changes

state of object

Page 5: Overview of Course

Data Abstraction and Encapsulation

• Objects– sports car– string of characters– array of objects

• Details of structure (implementation) unimportant

• Interface (contract) important

A p p l e

0 1 2 3 4 5 6

data

Page 6: Overview of Course

Object Model

• Data for program managed by its objects

• Program manipulates data through messages or method calls to the objects

Page 7: Overview of Course

Object-Oriented Terminology

• Data abstraction is accomplished through encapsulation of data in an object (an instance of a class)

• Fields and methods may be declared public or protected

• Fields are encapsulated by a class• Classes are encapsulated by a package• Public classes may be used by anyone

who imports the package

Page 8: Overview of Course

Example: class Ratio

• Interface– public Ratio(int top, int bottom)– public int getNumerator()– public int getDenominator()– public double value()– public Ratio add(Ratio other)

Page 9: Overview of Course

Example: class WordList

• WordList, initially empty, will contain words

• User must be able to add words to, retrieve words from, and remove words from WordList

• User must know when Wordlist empty

Page 10: Overview of Course

Example: class WordList

• Interface– public WordList(int size)– public boolean isEmpty()– public void add(String s)– public String selectAny()– public void remove(String word)

Page 11: Overview of Course

• We do not need to know anything about application other than its interaction with Object (abstract list of words)

• We really don’t know how WordList is implemented

• Result is the WordList interface

Example: class WordList

Page 12: Overview of Course

Example: class BankAccount

• Read on your own

• Pay attention to discussion of the method equals

Page 13: Overview of Course

Example: Linked Lists

• Refer to Program #1 handout

• Program #1– due Monday, August 31, 1998– handin.102.1 1 List.java– handin.102.1 1 ListNode.java– handin.102.1 1 LinkedList.java– handin.102.1 1 *.java

Page 14: Overview of Course

handin.102.1 1 *.javaSubmission for 102 section 1 asg number 1: LinkedList.java List.java ListNode.java

Do you wish to continue with the submission [y/n] yfile LinkedList.java: 3642 bytes copiedfile List.java: 993 bytes copiedfile ListNode.java: 227 bytes copied

handin command

Page 15: Overview of Course

Example: An Association

• Pig Latin translator• Example of (key-value) pair• Example of precondition

• Principle 2: – Free the future: reuse code

Page 16: Overview of Course

Interfaces• Sometimes useful to describe the interface for a

number of different classes without committing to an implementation

• No code specified in an interface

• Interfaces may be extended

• Example: public interface Store public interface Collection extends Store

Page 17: Overview of Course

Example: Extending Interfaces

• public interface Store– public int size()– public boolean isEmpty()– public void clear

• public interface Collection extends Store– public boolean contains(Object value)– public void add(Object value)– public Object remove(Object value)– public Iterator elements()

Page 18: Overview of Course

Conclusions

• Principle 3: Design and abide by interfaces as though you were the user

• Principle 4: Declare data fields protected

• Data abstraction is supported by separating the interface from the implementation of the data structure

Page 19: Overview of Course

Homework #1

• Problems 1.10, 1.11, 1.13 of textbook

• Assigned August 26, 1998• Due September 2, 1998• Refer to printed handout

distributed in class

Page 20: Overview of Course

Program #2 (?)

• Problems: 1.6, 1.7• Refer to Program #2 handout

• Due: September 9, 1998