Introduction to Computer Science and Object-Oriented Programming

Slides:



Advertisements
Similar presentations
Chapter 8: Designing Classes
Advertisements

Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Designing Classes Chapter 8. Classes Collection of objects Objects are not actions Class names – Nouns Method names – Verbs What Makes a Good Class Represent.
Chapter 9: Searching, Sorting, and Algorithm Analysis
Chapter 7 Designing Classes Goals  To learn how to choose appropriate classes to implement  To understand the concepts of cohesion and coupling  To.
Class Design CSC 171 FALL 2004 LECTURE 11. READING Read Chapter 7 It’s abstract But it should help with project #1.
Searching and Sorting Arrays
CSS446 Spring 2014 Nan Wang.  To learn how to choose appropriate classes for a given problem  To understand the concept of cohesion  To minimize dependencies.
CS1101: Programming Methodology Aaron Tan.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
INFO Problem Solving and Programming Logic INFO Problem Solving and Programming Logic Arrays Sorting.
Week 12 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
CS1101: Programming Methodology Aaron Tan.
1 Today’s Material Iterative Sorting Algorithms –Sorting - Definitions –Bubble Sort –Selection Sort –Insertion Sort.
Computer Science 101 Introduction to Sorting. Sorting One of the most common activities of a computer is sorting data Arrange data into numerical or alphabetical.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
1 Sorting. 2 Introduction Why is it important Where to use it.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
In the first pass, the first two numbers are compared. The shuttle sort compares the numbers in pairs from left to right exchanging when necessary.
A High Flying Overview CS139 – Fall 2006 How far we have come.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Chapter 7 Designing Classes. Chapter Goals  To learn how to choose appropriate classes to implement  To understand the concepts of cohesion and coupling.
CSCI 51 Introduction to Programming March 10, 2009.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
Further Modularization, Cohesion, and Coupling. Simple Program Design, Fourth Edition Chapter 9 2 Objectives In this chapter you will be able to: Further.
CISC124 - Notices Assn 2 due this Friday. You already know what you need to do this assignment: –Another procedural program. –Uses text file I/O (see Exercise.
Sort Algorithm.
Sorting Chapter 14.
CSC 222: Object-Oriented Programming
CSC 222: Computer Programming II
CSSE 220 Day 17 Introduction to your Vector Graphics project
Objects First with Java A Practical Introduction using BlueJ
CSC 427: Data Structures and Algorithm Analysis
Introduction to Search Algorithms
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Lecture 7 Designing Classes
3.1 Algorithms (and real programming examples).
3.3 Fundamentals of data representation
Algorithm Analysis CSE 2011 Winter September 2018.
Introduction to Computer Science and Object-Oriented Programming
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CS139 – Fall 2010 How far we have come
Algorithm Efficiency and Sorting
Algorithms Chapter 3 With Question/Answer Animations
Consecutive Integers: Numbers are one apart
Shuttle Sort Example 1st pass Comparisons: 1
ITEC 2620M Introduction to Data Structures
MSIS 655 Advanced Business Applications Programming
Sort Techniques.
Straight Selection Sort
Standard Version of Starting Out with C++, 4th Edition
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
Software Design Lecture : 9.
Programs and Classes A program is made up from classes
Searching and Sorting Arrays
Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders
Cohesion and Coupling.
Introduction to Sorting Algorithms
Shuttle Sort Example 1st pass Comparisons: 1
Principles of Computing – UFCFA3-30-1
CS148 Introduction to Programming II
CS Problem Solving and Object Oriented Programming Spring 2019
Presentation transcript:

Introduction to Computer Science and Object-Oriented Programming Week 11

Tonight Lab 5 Chapter 8 Week 11

Bubble Sort Simple sort Think of regions … … next place to bubble [0] … … sorted unsorted “Bubble through the unsorted region, to place then next value to it’s correct position Week 11

Bubble Sort Compare the first two elements of the array. If the first element is larger than the second Then swap them Otherwise, leave them alone. Repeat this step for the second and third element then the third and fourth and so on. At the end of the first pass the last number in the array is the largest. Repeat for as many times as elements in the array Week 11

Bubble Sort Pass Week 12

Bubble Sort 11 9 17 5 12 11 9 17 5 12 9 11 5 12 17 Initial state Begin first pass 1st pass compare pattern: 9 11 5 12 17 Begin second pass 2nd pass compare pattern: Week 11

Bubble Sort 9 5 11 12 17 5 9 11 12 17 5 9 11 12 17 Begin third pass 3rd pass compare pattern: 5 9 11 12 17 Begin forth pass 4th pass compare pattern: 5 9 11 12 17 Final state Week 11

Code for Bubble Sort Week 12

An Optimization Propagates up in one direction but down in the other So… It may get sorted before final pass! Week 12

With the Optimization Week 12

Object Oriented Design Two common approaches for problem solving: Procedural Approach Identify tasks break down to lowest level Object Oriented Approach Identify objects Identify data (instance fields) Identify procedures (methods)

OOD Begins with identifying classes (objects) Class names should be nouns not DetermineGrade, OrderAutomobile easy with most objects: Grade, Automobile, Coin, Customer some classes not as easy: Scanner, MazeResultDriver Classes should represent a single concept from the problem domain

Example: Student as a class Cohesion Cohesion The public interface of class relates just to the class concept. High cohesion is good when designing a class (represents a single concept) Example: Student as a class But poor cohesion if it ontains methods to list times when courses are offered

Coupling Level to which classes are dependent on each other A class X is dependent on another class Y if a change to Y could require a change in X Low coupling is good when designing a class

Categories of Classes Classes fall into 4 categories: Domain Classes Nouns, related to problem set (e.g., Employee, CompactDisc, Time, Skier) Represent single concept, non-programmer recognizes Actor Classes Verbs, related to problem set (e.g., TaxCalculator, ReportPrinter, MazeResultDriver) Usually a process or action, often end in -er or -or

Categories of Classes Classes fall into 4 categories: Utility Classes Provides reusable services across many problem sets (e.g., Math) Typically, only static methods and constants, no instantiation Library Classes Provides reusable components across many problem sets (e.g., String, ArrayList) Instantiation required, are true objects

Accessor / Mutator methods Two types of methods for class: Accessor does not change the object (instance fields) Mutator changes the object’s instance fields

Immutable Classes Immutable class has no mutator methods (no methods can alter the value of the data in the object) Example is String class String newName = name.toLowerCase( ); String str2 = str1.substring(start, end); Another example is Wrapper classes (Double, Integer) Call to intValue( ) method of Double class does not change the value of the Double variable