COMP 14 Introduction to Programming Miguel A. Otaduy May 24, 2004.

Slides:



Advertisements
Similar presentations
Unified Modeling Language
Advertisements

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Chapter 41 Defining Classes and Methods Chapter 4.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough October 1, 2007.
Intro to Object-Oriented (“OO”) Design. OO Design Simplified methodology 1. Write down detailed description of problem 2. Identify all (relevant) nouns.
Chapter 11: Classes and Data Abstraction
Software Engineering Principles and C++ Classes
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 1 Program Design
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Introduction To Object-Oriented Programming. Object-Oriented Programming Class: Code that defines the behavior of a Java programming element called an.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Simple Program Design Third Edition A Step-by-Step Approach
Sadegh Aliakbary Sharif University of Technology Fall 2011.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Data Structures Using C++1 Chapter 1 -Software Engineering Principles -ADT and Classes.
Chapter 8: User-Defined Classes and ADTs
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
1 Chapter-01 Introduction to Software Engineering.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 12: Classes and Data Abstraction.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
1 Chapter-01 Introduction to Software Engineering.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
1 CS 132 Spring 2008 Chapter 1 Software Engineering Principles and C++ Classes.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Engineering Problem Solving With C An Object Based Approach
Java Programming: From Problem Analysis to Program Design,
Anatomy of a Class & Method
Chapter 4: Writing Classes
User-Defined Classes and ADTs
Chapter 8: User-Defined Classes and ADTs
Chapter 1 Introduction(1.1)
User-Defined Classes and ADTs
CiS 260: App Dev I Chapter 6: GUI and OOD.
Methods/Functions.
Presentation transcript:

COMP 14 Introduction to Programming Miguel A. Otaduy May 24, 2004

COMP 14 So Far... Problem Solving Mathematical Calculations Output User Input File I/O Selection (if, if-else, switch) Loops (while, do...while, for)

COMP 14 Next... Object-Oriented Design Writing Methods –pieces of code that we give a name Writing Classes –organize related pieces of information Arrays –access multiple pieces of information with a single identifier

Object-Oriented Design What is it? Designing a solution to a problem by first identifying components called objects, and determining how the objects interact with each other

Objects VCR Example Use it without knowing how it's made Internal parts are hidden -- only interact with the provided buttons Can't modify the functions of a VCR -- record button always records, play button always plays Same is true for objects (like Strings) that are provided by Java

Objects Consists of data and operations on the data Data - descriptive characteristics Operations - what it can do (or what can be done to it) Example A coin that can be flipped so that its face shows either "heads" or "tails" –data: its current face (heads or tails) –operations: it can be flipped Operations can change data.

Objects And Methods and Classes We represent operations with methods –group of statements that are given a name We can use objects and their methods without knowing exactly how the methods work An object is an instance of a class. A class is the blueprint of an object. –the class provides the methods that can operate on an object of that class

Classes A class contains data declarations and method declarations A class is a description of an object –just a model, not an actual object –you can think of the concept of a book without thinking of a particular book A class is no more an object than a blueprint is an actual house

Object-Oriented Design Simplified Methodology 1. Write down detailed description of problem 2. Identify all (relevant) nouns and verbs 3. From list of nouns, select objects 4. Identify data components of each object 5. From list of verbs, select operation

Object-Oriented Design Example 1 Problem Statement –Write a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle

Example 1 Building a Rectangle Identify nouns –length, width, rectangle, perimeter, area Identify each class –length of a rectangle –width of a rectangle –perimeter of a rectangle –area of a rectangle

Example 1 Building a Rectangle Identify data members for each class –nouns: length, width, area, perimeter –what are the essential nouns for describing the rectangle? –area and perimeter can be computed if we know the length and width

Example 1 Building a Rectangle Identify operations for each class –input, calculate, print –setLength –setWidth –computePerimeter –computeArea –print –getLength –getWidth directly from problem statement customary to include operations to get the value of the data members

class Rectangle Data Members and Operations Last Step: design and implement an algorithm for each operation class name data members operations (methods)

Anatomy of a Class A class contains data declarations and method declarations int width; int length; Data declarations Method declarations (operations)

Classes and Objects Rectangle A class (the concept) length = 15, width = 3 An object (the realization) length = 20, width = 6 length = 15, width = 15 Multiple objects from the same class

Object-Oriented Design Example 2 A place to buy candy is from a candy machine. A new candy machine is bought for the gym, but it is not working properly. The candy machine has four dispensers to hold and release items sold by the candy machine and a cash register. The machine sells four products —candies, chips, gum, and cookies—each stored in a separate dispenser. You have been asked to write a program for this candy machine so that it can be put into operation. multiple objects/classes (pgs )

Non-Concrete Objects Objects in programs don't always have real-world analogs Example object: error message data: text of the error message operation: print the text of the error message to the screen

Next in Comp14 Tomorrow: writing methods Wednesday: review for mid-term –Bring laptops –Write questions before coming to class