1 CS1110 7 Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.

Slides:



Advertisements
Similar presentations
1 For more info: CS Sep 2008 In 1968, the Defense Department hired Bolt Beranek and Newman (BBN) of Boston to.
Advertisements

1 CS100J. Lecture 2, 25 January 2007 Today’s topic: Objects and classes Reading for this lecture: Section 1.3. It’s most important that you study this.
CS100J Today’s topic: Objects and classes Reading for this lecture: Section 1.3 PLive: Activities 3-3.1, 3-3.2, (not 3-3.3), 3-4.1, Summary.
1 CS Sept. Customizing a class & testing Quiz 2 on Tuesday 15 Sept Purpose of a constructor (slide 5) Evaluating a new expression (slide 6) Fields;
1 CS100J 1 February Customizing a class & testing Quote for the day: There is no reason anyone would want a computer in their home. - -Ken Olson,
1 Review of classes and subclasses M fast through this material, since by now all have seen it in CS100 or the Java bootcamp First packages Then classes.
CS100J 11 September 2003 Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to see how.
0 CS100J September 2007 CS100J: 12 weeks programming using Java, 2 using Matlab. David Gries. CS100M: 7 weeks of Matlab and 7 of Java. Daisy Fan. CS100H:
CS100J CS100M is in Kimball Bll. Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to.
1 CS100J 18 September 2007 More on Methods. Developing methods. Also: The inside-out rule; and the use of this and super. Read sec. 2.5 on stepwise refinement.
1 CS100J 30 January 2007 The class definition Course Management System (CMS) for CS100J is populated with students who were pre-registered. Look at course.
1 CS100J 05 February 2005 Today’s topic: Customizing a class (continued) Quiz 1 is today Quiz 2 is next Tuesday Quote for the day: There is no reason anyone.
1 CS1130 Spring 2011: David Gries & Walker White Transition to Object-Oriented Programming Assumes programming knowledge in a language like Matlab, C,
1 CS1110 Fall 2011: David Gries & Steve Marschner CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering- type problems.
CS/ENGRD 2110 FALL 2014 Lecture 3: Fields, getters and setters, constructors, testing 1.
Quote for the day: Computational thinking: a fundamental skill for everyone … [It] is … choosing an appropriate representation for a problem or modeling.
Teaching OO to Beginners David Gries Computer Science, Cornell Past 3-4 years: Teach computing using Java students each semester Mostly Engineering,
UML Basics & Access Modifier
1 CS1110 Fall 2010 Instructors: David Gries & Lillian Lee CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering-
CS/ENGRD 2110 SPRING 2015 Lecture 3: Fields, getters and setters, constructors, testing 1.
Quote for the day: Computational thinking: a fundamental skill for everyone … [It] is … choosing an appropriate representation for a problem or modeling.
Recitation 2 Main Method, API & Packages, Java Basics.
1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.
1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:
CSC 212 – Data Structures Lecture 12: Java Review.
Week 3 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CS100J 09 September 2003 Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to see how.
CS1110 lecture 5 14 Sept 2010 Testing; the class Object; toString; static variables & methods Reading for this lecture: Testing with JUnit (Appendix I.2.4.
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
0 Teaching Java —with OO first David Gries Computer Science Cornell University Ithaca, NY
Index of Learning Styles
1 CS1110 lecture 4 9 Sept. Customizing a class & testing Classes: fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105–110 only) Constructors.
1 CS Sept 2010 Inside-out rule; use of this, super Developing methods (using Strings). Read sec. 2.5, stepwise refinement Listen to Plive, 2.5.1–2.5.4.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
CS/ENGRD 2110 SPRING 2012 Lecture 2: Objects and classes in Java 1.
CS1110 lecture 5 8 Feb 2010 Testing; class Object; toString; static variables/methods Reading for this lecture: Testing with JUnit (Appendix I.2.4 & pp.
1 CS1110 lecture 4 9 Sept. Customizing a class & testing Classes: fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105–110 only) Constructors.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
1 CS1100 Fall Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems CS100J:
1 CS1110 Fall Instructors: David Gries & Lillian Lee CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering-
Principled approach to teaching OO first David Gries Computer Science, Cornell 1.
1 CS100J 08 September 2005 Today’s topic: Customizing a class (continued) Quote for the day: There is no reason anyone would want a computer in their home.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
1 CS1110 Stepwise refinement, more on classes 24 Sep 2009 Application of String processing and stepwise refinement. Miscellaneous points about classes.
1 CS1110. Lecture 2, 28 Jan Objects & classes PLive: Activities 3-3.1, 3-3.2, (not 3-3.3), 3-4.1, Summary of lectures: On course page,
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
1 For more info: CS February 2009 In 1968, the Defense Department hired Bolt Beranek and Newman (BBN) of Boston.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Class Definitions and Writing Methods Chapter 3 3/31/16 & 4/4/16.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
1 CS Sept Customizing a class & testing Quote for the day: There is no reason anyone would want a computer in their home. - -Ken Olson, founder.
CS/ENGRD 2110 Fall 2017 Lecture 2: Objects and classes in Java
CS Feb 2010 Customizing a class
CS1110 Spring Instructor: David Gries
Lecture 10 Review of classes
CS1110 Classes, stepwise refinement 23 Sep 2009
CS100J. Lecture 2, 24 September Objects & classes
CS/ENGRD 2110 Spring 2018 Lecture 2: Objects and classes in Java
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
CS 1110 Please do this now. Draw three variables on a piece of paper as shown to the right: b 4 c 7 d false Below is a “program” consisting of 3 assignment.
CS100J 06 September 2005 The class definition
CS/ENGRD 2110 Fall 2018 Lecture 2: Objects and classes in Java
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
Concepts for this lecture: Class Instance of a class, (an object)
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
CS Feb 2011 Customizing a class
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and I can assure you that data processing is a fad that won't last out the year. —Editor in charge of business books for Prentice Hall, 1957 Reading for this lecture: Sections 1.4, (p. 41); (p. 376). Read all “style notes” and referenced PLive lectures (activities). Summary of lectures: On click on “Lecture summaries” Reading for next lecture: Fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105– 110 only) Constructors. Sec (p. 110– 112) Testing. App. I.2.4 (p. 486)

22 One-on-One Sessions Next two weeks, 1/2-hour one-on-one session on a computer with each student in CS1110 Purpose: See how well you understand what we have done, let you ask questions, give you help. Graded 0-1: 1 if you did a session. Not counted in course grade. Purpose: to help you. Instructors : Gries, Lee, TAs, consultants. How to sign up: Visit CMS. Click on assignment One-on-one. Choose from list of times/instructors. First-come-first-served.

People learn differently. active versus reflective learners learn by doing vs. learn by reflection; groupie vs. loner sensing versus intuitive learners practical/careful vs. fast/innovative visual versus verbal learners pics, charts, films vs. words, explanations sequential versus global learners logical, step-by-step, bottom-up vs. big-picture 3 Learning styles Course outline webpage has link to website of Felder and Brent where you can read about this and take a self-scoring test to see your strengths/weaknesses

4 c1 Patient name “B. Clinton” address “New York” owes $ getName() deposit(double d) x has value 6 y has value c1 y.getName() has the value “B. Clinton” y.deposit(250) ; will change the value of field owes to 0. x 6 y c1 int Patient This reviews what we did last time. function call procedure call name of folder fields (they are variables) assume is a function assume is a procedure class (type) of this object

5 Class javax.swing.JFrame: an object is a window on your monitor. x j1 y j2 j1 JFrame setTitle(String) getTitle() getX() getY() setLocation(int,int) getWidth() getHeight() setSize(int,int) … new JFrame() Expression: create a new object of class JFrame and yield its name This reviews what we did last time.

6 Class definition: The java construct that describes the format of a folder (instance, object) of the class. /** description of what the class is for */ public class { } declarations of methods (in any order) This is a comment A class definition goes in its own file named. java On your hard drive, have a separate directory for each Java program that you write; put all the class definitions for the program in that directory.

7 Class definition for a new subclass: /** description of what the class is for */ public class C { } declarations of methods (in any order) extends Class C has all the fields and methods that does, in addition to those declared in C. Class C inherits the fields and methods of.

a0 superclass-name subclass-name methods and fields inherited from superclass-name methods and fields declared in subclass-name 8 /** description of what the class is for */ public class subclass-name extends superclass-name { declarations of methods } folder (object) belongs in file drawer for class subclass-name

9 /** description of what the class is for */ public class subclass-name extends superclass-name { /** Set the height of the window to the width */ public void setHeightToWidth() { } /** = the area of the window */ public int area() { } return getWidth() * getHeight(); Note the specifications (comments) on the methods. setSize(getWidth(), getWidth()); First example of a procedure and of a function.

10 import javax.swing.*; /** An instance is a JFrame with methods to square it and to provide the area of the JFrame */ public class SquareJFrame extends JFrame { …declarations of methods… } folder (object) belongs in file drawer for class SquareJFrame To the left, draw a manila folder of class SquareJFrame. When we define methods, put them in the proper place

11 import javax.swing.*; /** An instance is a JFrame with methods to square it and to provide the area of the JFrame */ public class SquareJFrame extends JFrame { /** = the area of the window */ public int area() { … } /** Set the height equal to the width */ public void setHeightToWidth() {…} } Javadoc The class and every method in it has a comment of the form /** specification */ It is a Javadoc comment. Click on javadoc icon in DrJava to extract class specification. DO THIS AT LEAST ONCE IN LAB.

12 About null var1 c1 var2 c8 var3 null c1 Patient c8 Patient null denotes the absence of a name. var3.getName() is a mistake! You get a NullPointerException.