



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CMPU-101: Problem-Solving and Abstraction Marc Smith (sect. 52) Vassar College Fall 2006 2
Idea: Programs should closely model the real world. Claim: Such programs are easier to write & maintain. Must be able to translate between:
Object-Oriented Design:
5
ClassName data methods A visual language for describing and designing classes and class relationships Two types of class relationships: is-a, has-a 6
Account owner balance accountNumber Account(…) — constructor getBalance deposit withdraw addInterest
Account owner balance accountNumber Account(…) getBalance deposit withdraw addInterest
Person name ssn dateOfBirth address Person(…) — constructor setName setAddress ! Employee dateHired monthlySalary
13
Account allows getBalance and withdraw. PrintStream allows print and println. 14
Student name ssn dateOfBirth gpa Sometimes in a UML diagram, we show only the fields of the class, depending on our purpose
Section roster instructor room timeSlot Section(…) — constructor addStudent(Student) removeStudent(Student) contains(Student) intersect(Section) In this case, roster is a collection of Student s - - a one-to-many, has-a relationship! (one Section has many Student s)
Composed of: letters digits underscore ("_") Must begin with a letter. Examples: timeToLive bistro U MAXIMUM_VALUE
17
Classes — all words are capitalized Account BankAccount ClosedCurve Matrix3By Instances — the first word is not capitalized cs numberOfStudents averageAge taxRate 18
Reserved words class, public, private, static, … (see Appendix Two) Names defined by other programmers in the API System.out, println, PrintStream Names we select
Given a problem, we must answer the questions: What are the classes? What are the methods? What are the instance variables? Written assignment: choose from Chapter 2 Exercises