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.
CS 1110 Prelim I: Review Session. Exam Info Prelim 1: 7:30–9:00PM, Thursday, 6 October, Statler Auditorium Look at the previous Prelims Arrive early!
CS 1110 Prelim I: Review Session. Introduction My name: Bruno Abrahao – We have four TA’s in the room to help you individually Shuang Zhao Nam Nguyen.
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 20 September 2005 More on Methods. Developing methods Also: About the use of this and super Read section 2.5 on stepwise refinement Listen to.
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.
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.
1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:
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
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.
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.
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 CS1110 Stepwise refinement, more on classes 24 Sep 2009 Application of String processing and stepwise refinement. Miscellaneous points about classes.
1 CS1110 Classes, stepwise refinement 17 Feb 2009 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of.
1 CS September 2008 Discussion of Methods: Executing method calls.If-statements. The return statement in a function. Local variables. For this and.
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 CS1110 Thursday, 10 Feb 2011 Discussion of Methods: Executing method calls. If-statements. The return statement in a function. Local variables. For this.
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.
1 CS Sep 2011 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of class text Need Help? Make.
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.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
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.
1. Understanding the execution of local variable declaration (in a method body) new expression ( 3 steps ) method call (method frames, call stack) examples.
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.
Sit next to someone. Today, we do some work in pairs.
CS100J 06 September 2005 The class definition
CS/ENGRD 2110 Fall 2018 Lecture 2: Objects and classes in Java
Sit next to someone. Today, we do some work in pairs.
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
CS 1110 Prelim I: Review Session Spring 2011
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
CS100J 22 February 2005 More on Methods. Developing methods
CS Feb 2011 Customizing a class
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)

IS AVAILABLE FOR THIS COURSE AT Questions? 409 College Ave FREE DELIVERY TO NORTH AND WEST CAMPUS

33 Informal Lunch with Gries or Lee About once a week, perhaps a bit more. 8 students max at a time. Sign up on the CMS. 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 4 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 See 6 Sept NY Times article “forget what you know about good study habits: tinyurl.com/29f3vzx

5 QUIZ 1. Get out a blank piece of paper. 2. Write your LAST name, FIRST name, and Cornell NetID (not your Cornell ID. Gries’s NetID is djg17) 3. Put two variables on the page, exactly like this: x y 4. Write down, in English, how to execute this assignment statement (don’t explain how to evaluate the expression x+y–1): y= x + y – 1; 5. Execute this assignment statement, using the two variables you previously drew on your piece of paper. 94

6 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

7 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. A. It’s all obvious, a piece of cake B. I’m okay, although I don’t get it all C. I’m rather neutral. I can see it but I have to study more D. I’m very apprehensive about this course E. I don’t understand anything

8 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.

9 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 10 /** 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

11 /** 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.

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… } 12 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 An object of class java.util.Date contains the date and time at which it was created. It has a function toString(), which yields the date as a String. Write a procedure setTitleToDate, which will set the title of the window to the date. An object of class java.util.Date contains the date and time at which it was created. It has a function toString(), which yields the date as a String. Write a procedure setTitleToDate, which will set the title of the window to the date. Body is: A. setTitle(new java.util.Date()); B. setTitle(“” + new java.util.Date()); C. setTitle(new java.util.Date().toString()); D. None of these E. I don’t know

13 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.

14 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.