CS Feb 2010 Customizing a class

Slides:



Advertisements
Similar presentations
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Advertisements

1 For more info: CS Sep 2008 In 1968, the Defense Department hired Bolt Beranek and Newman (BBN) of Boston to.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
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,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Java boot camp1 Subclasses Concepts: The subclass and inheritance: subclass B of class A inherits fields and methods from A. A is a superclass of B. Keyword.
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.
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.
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
Quote for the day: Computational thinking: a fundamental skill for everyone … [It] is … choosing an appropriate representation for a problem or modeling.
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.
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.
The Java Inheritance Hierarchy CSIS 3701: Advanced Object Oriented Programming.
A brief introduction to javadoc and doxygen Cont’d.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
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
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.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
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.
A brief introduction to doxygen. What does a compiler do?  A compiler ignores comments and processes the code.  What does doxygen do? –It ignores the.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
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. 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 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 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.
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
Inheritance ITI1121 Nour El Kadri.
Lecture 10 Review of classes
CS100J. Lecture 2, 24 September Objects & classes
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
CS/ENGRD 2110 Spring 2018 Lecture 2: Objects and classes in Java
CS/ENGRD 2110 Fall2017 Lecture 4: The class hierarchy; static components
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
CS/ENGRD 2110 Spring 2016 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.
CS/ENGRD 2110 Fall 2018 Lecture 4: The class hierarchy; static components
CS100J 06 September 2005 The class definition
CS/ENGRD 2110 Fall 2018 Lecture 2: Objects and classes in Java
Chapter 11 Inheritance and Polymorphism
CS/ENGRD 2110 Spring 2019 Lecture 2: Objects and classes in Java
Concepts for this lecture: Class Instance of a class, (an object)
CS100J CS100M is in Kimball Bll.
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
CS100J Final Class on Classes 10 February 2005
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

CS1110 2 Feb 2010 Customizing a class Summary of lectures: On course home page, click on “Lectures” and then on “Outline of lectures held so far”. Reading for this lecture: Sections 1.4, (p. 41); 13.3.1 (p. 376). Read all “style notes” and referenced PLive lectures (activities). 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 next lecture: Fields; getter & setter methods. Secs 1.4.1 (p. 45) & 3.1 (pp. 105–110 only) Constructors. Sec. 3.1.3 (p. 111–112) Testing. App. I.2.4 (p. 486)

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

y.getName() has the value “B. Clinton” name of folder c1 Patient name “B. Clinton” address “New York” owes $250.00 getName() deposit(double d) x 6 int fields (they are variables) y c1 Patient function procedure 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. This reviews what we did last time. function call procedure call

Class javax.swing.JFrame: an object is a window on your monitor. setTitle(String) getTitle() y j2 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 class definition goes in its own file named 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 <class-name> { } This is a comment declarations of methods (in any order) A class definition goes in its own file named <class-name> . 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.

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 C { } extends <superclass-name> declarations of methods (in any order) Class C has all the fields and methods that <superclass-name> does, in addition to those declared in C. Class C inherits the fields and methods of <superclass-name>.

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

First example of a procedure and of a function /** 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() { setSize(getWidth(), getWidth()); return getWidth() * getHeight();

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

Javadoc 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() {…} } 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.

Javadoc 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() {…} } 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.

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