University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 12, Mon Feb 1 2010

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Mathematical Operations, Static Methods Lecture 9, Thu Feb 2.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner 1 Interfaces, Polymorphism II Lecture 21, Thu Mar
1 Fall 2009ACS-1903 Methods – Ch 5 A design technique referred to as stepwise refinement (or divide and conquer, or functional decomposition) is used to.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner 1 Advanced Class Design Lecture 19, Thu Mar
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Class Design Lecture 9, Mon Jan
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 11, Fri Jan
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Mathematical Operators, Static Methods Lecture 14,
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Class Design Lecture 6, Tue Jan
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Static Methods, Conditionals Lecture 15, Mon Feb 8.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops III Lecture 20, Fri Mar
1 Classes, Encapsulation, Methods and Constructors Class definitions Scope of Data –Instance data –Local data The this Reference Encapsulation and Java.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops I Lecture 17, Fri Feb
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Loops II Lecture 13, Thu Feb
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 30, Mon Mar
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Loops Lecture 12, Tue Feb
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Interfaces, Polymorphism Lecture 29, Fri Mar
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 10, Wed Jan
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner 1 Arrays and Class Design Lecture 18, Tue Mar
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Conditionals II Lecture 11, Thu Feb
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Objects, Class Design Lecture 8, Fri Jan
Slide 1. Slide 2 Administrivia Nate's office hours are Wed, 2-4, in 329 Soda! TA Clint will be handing out a paper survey in class sometime this week.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 13, Wed Feb
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops II Lecture 18, Mon Mar
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design III, Parameter/Scope Review Lecture.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
© Xiaoying Gao, Peter Andreae Introduction to Computer Program Design COMP T2. Xiaoying (Sharon) Gao Computer Science Victoria University of Wellington.
A1 Visual C++.NET Intro Programming in C++ Computer Science Dept Va Tech August, 2002 © Barnette ND & McQuain WD 1 Quick Introduction The following.
Style Comments About HW 1 Use #define !!! –All of you already know the reasons for using symbolic constants …but most of you didn’t use #define in HW1.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Utilities (Part 2) Implementing static features 1.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
© Xiaoying Gao, Peter Andreae Introduction to Computer Program Design COMP T2. Xiaoying (Sharon) Gao Computer Science Victoria University of Wellington.
Agenda Object Oriented Programming Reading: Chapter 14.
CS 123 Engineering Computation Lab Lab 2 Dan De Sousa and Bruce Char Department of Computer Science Drexel University April 2009 ©By the author. All rights.
Monday, Jan 6, 2003Kate Gregory with material from Deitel and Deitel CO 204 Object Oriented Programming 2003 Trent University Kate Gregory.
© 2004 Pearson Addison-Wesley. All rights reserved September 12, 2007 Encapsulation ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
1 CS161 Introduction to Computer Science Topic #9.
© 2004 Pearson Addison-Wesley. All rights reserved September 14, 2007 Anatomy of a Method ComS 207: Programming I (in Java) Iowa State University, FALL.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
1  lecture slides online
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
CSC 212 – Data Structures Lecture 5: Variables. Problem of the Day Why do underground subway stations always have more escalators going up than down?
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
INTRODUCTION: WELCOME TO STAT 200 January 5 th, 2009.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
PROBLEM SOLVING AND PROGRAMMING ISMAIL ABUMUHFOUZ | CS 170.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
Winter 2006CISC121 - Prof. McLeod1 Last Time Reviewed class structure: –attributes –methods –(inner classes) Looked at the effects of the modifiers: –public.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Class Design II Lecture 7, Thu Jan
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
Defining Classes and Methods
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Writing Functions.
CS360 Client/Server Programming Using Java
Final Review Bina Ramamurthy 4/5/2019 BR.
Intro to CIT 594
Classes CS 21a: Introduction to Computing I
Presentation transcript:

University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design Lecture 12, Mon Feb borrowing from slides by Paul Carter and Steve Wolfman

2 Department of Computer Science Undergraduate Events Events this week Resume Editing Drop-In Session Date: Mon., Feb 1 Time: 11 am – 2 pm Location: Rm 255, ICICS/CS EADS Info Session Date: Mon., Feb 1 Time: 3:30 – 5:30 pm Location: CEME 1202 Job Interview Practice Session (for non-coop students) Date: Tues., Feb 2 Time: 11 am – 1 pm Location: Rm 206, ICICS/CS RIM Info Session Date: Thurs., Feb 4 Time: 5:30 – 7 pm Location: DMP 110 Events next week Finding a Summer Job or Internship Info Session Date: Wed., Feb 10 Time: 12 pm Location: X836 Masters of Digital Media Program Info Session Date: Thurs., Feb 11 Time: 12:30 – 1:30 pm Location: DMP 201

3 Reminders n Assignment 1 due Wed 5pm n TA office hours in DLC n n my office hours 4-5pm today in X661

4 News: Lab Schedule Change n no labs next week Feb 8-12 n TAs will hold office hours in labs during Monday lab times to answer pre-midterm questions n Mon Feb 8 11am - 3pm ICICS 008 n labs resume after break n staggered to ensure that even Monday morning labs have seen material in previous week's lecture

5 Midterm Coverage n reading: chapters 1-4 n lectures: weeks 0-4 n through this Friday 2/5 n topics: n intro, hardware background, programming languages, comments, identifiers, whitespace, errors, variables, primitive data types, assignment, casting, constants, objects, classes, strings, input, class design n assignments: n assignment 1

6 Midterm Format n closed book, no notes, no calculators n must bring ID, put in front of you face up so we can see picture and name n 6:30 Monday 2/8, FSC 1005 n exam starts at 6:30, please arrive before that n you will have 60 minutes to do the exam n do not turn over or open exam until we say to begin

7 Midterm Advice n good to read book, but definitely don't stop there! n best thing to do: practice programming n try exercises in Big Java n solutions for some practice problems now posted in new Handy Links folder on WebCT Vista n and/or invent your own problems! n do a mix of programming on the computer, and on paper n you will only have paper for the exam

8 Reading Assignment This Week n Chap re-read

9 Recap: UML Visual Syntax n + for public, - for private n fields above, methods below Classname fields methods + field: type - method(): return type + Classname() + method(): return type + method(param1 type, param2 type): return type - field: type

10 Recap: Control Flow Between Modules n Two weeks ago it was easy to understand control flow: order in which statements are executed n march down line by line through file n Now consider control flow between modules int rollResult; myDie.setSides(); rollResult = myDie.roll(); public int roll() { … } public void setSides() { … } Client code Die class methods

11 Recap: UML Design for Point n preliminary design for 2D point class Classname fields methods - x: double + Classname(inX: double, inY: double) + distanceBetween(Point otherPoint): double - y: double

12 Continuing: Implementing Point public class Point { }

13 Formal vs. Actual Parameters n formal parameter: in declaration of class n actual parameter: passed in when method is called n variable names may or may not match n if parameter is primitive type n call by value: value of actual parameter copied into formal parameter when method is called n changes made to formal parameter inside method body will not be reflected in actual parameter value outside of method n if parameter is object: covered later

14 Scope n Fields of class are have class scope: accessible to any class member n in Die and Point class implementation, fields accessed by all class methods n Parameters of method and any variables declared within body of method have local scope: accessible only to that method n not to any other part of your code n In general, scope of a variable is block of code within which it is declared n block of code is defined by braces { }

15 Commenting Code n Conventions n explain what classes and methods do n plus anywhere that you've done something nonobvious n often better to say why than what n not useful int wishes = 3; // set wishes to 3 n useful int wishes = 3; // follow fairy tale convention

16 javadoc Comments n Specific format for method and class header comments n running javadoc program will automatically generate HTML documentation n Rules n /** to start, first sentence used for method summary tag for parameter name and explanation tag for return value explanation n n */ to end n Running % javadoc Die.java % javadoc *.java

17 javadoc Method Comment Example /** Sets the die shape, thus the range of values it can numSides the number of sides of the die */ public void setSides(int numSides) { sides = numSides; } /** Gets the number of sides of the the number of sides of the die */ public int getSides() { return sides; }

18 javadoc Class Comment Example /** Die: simulate rolling a die CPSC 111, Section 206, Spring Jan 31, 2006 * * This is the final Die code. We started on Jan 24, * tested and improved in on Jan 26, and did a final * cleanup pass on Jan 31. */

19 Cleanup Pass n Would we hand in our code as it stands? n good use of whitespace? n well commented? n every class, method, parameter, return value n clear, descriptive variable naming conventions? n constants vs. variables or magic numbers? n fields initialized? n good structure? n follows specification? n ideal: do as you go n commenting first is a great idea! n acceptable: clean up before declaring victory

20 Key Topic Summary n Generalizing from something concrete n fancy name: abstraction n Hiding the ugly guts from the outside n fancy name: encapsulation n Not letting one part ruin the other part n fancy name: modularity n Breaking down a problem n fancy name: functional decomposition