Midterms Save the Dates!

Size: px
Start display at page:

Download "Midterms Save the Dates!"

Transcription

1 University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Creating Your Own Class Lecture 7 Readings This Week s Reading: Ch (Major conceptual jump) Next Week: Review Ch 1-4 (that were previously assigned) (Reminder: Readings are absolutely vital for learning this stuff!) Some slides borrowed from Kurt Eiselt, Tamara Munzner, and Steve Wolfman. Some learning goals from Beth Simon. Labs and Tutorials This week is Lab #3. Lab #4 is up. Midterms Save the Dates! Midterm #1 is 5:30-6:30pm on February 10 (Tuesday) in Woodward IRC 2 Midterm #2 is 6-7pm on March 11 (Wednesday) in Woodward IRC 2 If you have a conflict with the first midterm, send me an with your name, student ID number, and a brief explanation of your conflict, by noon, Tuesday, February 3! Extra Credit Survey Dr. Ben Yu is studying attitudes towards learning in introductory CS classes. Three surveys to complete during the term. Survey 1 is on WebCT now. Due January 28 These are completely optional. PeerWise Instructions For people participating in PeerWise, instructions are now available on WebCT. Your first questions/answers must be done by February 9. If you have questions/problems, please contact Paul Denny. However, to encourage participation, I will give 1 pt of extra credit, applied to your labs, if you complete all three surveys in time. 1

2 WebCT Bulletin Boards I encourage you to read and ask questions on the WebCT bulletin boards: Faster response time: many TAs, both profs, and fellow students read and respond. Everyone benefits from answer. Learning Center The TAs mentioned that they are in the CS Learning Center, ready to help, but often nobody shows up. Just a reminder that TAs are there, and they want to help you! Learning Goals By the end of the next several lectures you will be able to Create your own classes, with: Public and private fields and methods Helpful documentation that works with javadoc Basic principles i of abstraction and encapsulation (information hiding) Explain why abstraction and information hiding are important. Learning Goals By the end of class today you will be able to Create your own new class. Create simple methods in your class. Call your methods from another class. Trace the execution flow between the two classes. Pass parameters to your methods and return values. Declare instance variables in your class, make them private, and create getters/setters From Using to Creating Like the difference between buying clothes versus designing and sewing clothes: Buyer: Browses stores, looks for the clothes they want, gets the clothes, and wears them. Designer/Tailor: Tries to design clothing that people want, creates patterns for making the clothing, makes lots of clothes. (Designer/Tailor is also a buyer: buying fabric, thread, buttons, beading, etc. Using simpler objects to create new objects.) From Using to Creating Like the difference between buying clothes versus designing and sewing clothes: Using Classes: Browse Java library, look for the classes we want, import them, and use them. Creating Classes: Try to design classes that people want, create patterns for making objects, make objects. (Creator is also a user: we ll often use objects when creating new objects.) 2

3 Wait! We ve been doing this already! A Simple Java Program // Our first Java program. /* Traditionally, one s first program in a new language prints out Hello, World! */ public class HelloWorld { public static void main(string[ ] args) { System.out.println( Hello, World! ); A Simple Java Program // Our first Java program. /* Traditionally, one s first program in a new language prints out Hello, World! */ public class HelloWorld { public static void main(string[ ] args) { System.out.println( Hello, World! ); Last Few Lectures: Using classes import java.math.biginteger; BigInteger salary; salary = new BigInteger( ); totalcompensation = salary.add(bonus); Using HelloWorld Using HelloWorld Not needed if.class file in same directory 3

4 Using HelloWorld Not needed if.class file in same directory HelloWorld foo; Using HelloWorld Not needed if.class file in same directory HelloWorld foo; foo = new HelloWorld(); Using HelloWorld Not needed if.class file in same directory HelloWorld foo; foo = new HelloWorld(); foo.main(null); // Don t worry about null Using HelloWorld Not needed if.class file in same directory HelloWorld foo; foo = new HelloWorld(); HelloWorld.main(null); // main is static Whoa what s going on? Sequential Execution Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. 4

5 Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. Bank Machine: Check PIN Check balance Dispense cash Dry Cleaner: Find clothes Deliver clothes Restaurant: Take order Prepare food Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. Bank Machine: Check PIN Check balance Dispense cash Dry Cleaner: Find clothes Deliver clothes Restaurant: Take order Prepare food Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. Bank Machine: Check PIN Check balance Dispense cash Dry Cleaner: Find clothes Deliver clothes Restaurant: Take order Prepare food Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. Bank Machine: Check PIN Check balance Dispense cash Dry Cleaner: Find clothes Deliver clothes Restaurant: Take order Prepare food Sequential Execution Suppose you have a list of tasks: Get money from bank machine. Pick up clothes from dry cleaner. Get lunch from takeout place. Bank Machine: Check PIN Check balance Dispense cash Dry Cleaner: Find clothes Deliver clothes Restaurant: Take order Prepare food Suppose you some Java statements: bonus = options.multiply(gain); p py(g ); total = salary.add(bonus); System.out.println(total); 5

6 Suppose you some Java statements: BigInteger Class: Suppose you some Java statements: BigInteger Class: bonus = options.multiply(gain); py(g total = salary.add(bonus); System.out.println(total); BigInteger multiply () { BigInteger add () { System Class: bonus = options.multiply(gain); py(g total = salary.add(bonus); System.out.println(total); BigInteger multiply () { BigInteger add () { System Class: Suppose you some Java statements: BigInteger Class: Suppose you some Java statements: BigInteger Class: bonus = options.multiply(gain); py(g total = salary.add(bonus); System.out.println(total); BigInteger multiply () { BigInteger add () { System Class: bonus = options.multiply(gain); py(g total = salary.add(bonus); System.out.println(total); BigInteger multiply () { BigInteger add () { System Class: How to Create a Class Suppose you some Java statements: BigInteger Class: Client Programmer: File MyClass.java bonus = options.multiply(gain); py(g total = salary.add(bonus); System.out.println(total); BigInteger multiply () { BigInteger add () { System Class: MyClass a; public class MyClass { 6

7 Client Programmer: How to Create a Class File MyClass.java Let s try it MyClass a; public class MyClass { a.sayhello(); public void sayhello() { System.out.println ( Hello ); Parameter Passing How do we get information into a method? We pass it parameters. ( pass as in passing the puck.) Creating New Methods Let s add a method for flattery: parameters Passing Parameters In the object user (the caller): a.flatter( fabulous ); In the class definition (the callee): Passing Parameters In the object user (the caller): a.flatter( fabulous ); In the class definition (the callee): 7

8 Review: Passing Parameters In the object user (the caller): a.flatter( fabulous ); adjective = fabulous In the class definition (the callee): Passing Parameters In the object user (the caller): a.flatter( fabulous ); adjective = fabulous In the class definition (the callee): Formal Parameters In the object user (the caller): a.flatter( fabulous ); In the class definition (the callee): The formal parameters define new variables. These are the types the method expects to get. Actual Parameters In the object user (the caller): a.flatter( fabulous ); In the class definition (the callee): The actual parameters are what gets passed when the method is called. Their values are copied into the formal parameters. Multiple Parameters? Let s add a method for flattery: formal parameters public void flatter(string interj, String adj) { System.out.println(interj + "You look " + adj + "!"); return Statement How do we get information back from the method? We use a return statement. ( return as in election returns results that come back to you) 8

9 return Statement The return statement in a method tells the method to return to the caller. Syntax: return; return expression; With an expression, it gets evaluated and that value is what the method call returns. Example Let s write a method that prints Hello on the screen and returns the number 42. (You ll use the return statement for much more interesting things later) Void Return Types Common confusion of output on screen versus returning a value. Can you say: int b = 3 + a.sayhello(); Void Return Types Common confusion of output on screen versus returning a value. Can you say: int b = 3 + a.sayhello(); No. sayhello returns type void. But we can use a method that has an int return type: int b = 3 + a.sayhelloandreturn42(); Questions? Objects Can Contain Variables It s convenient for objects to remember things about themselves, e.g.: java.awt.rectangle class in the book if we created a UBCStudent class To allow this, objects can have their own variables. Declare the variables in the class. But each (instance of an) object gets its own copy: Called instance fields or instance variables 9

10 Example Class: Celebrity public class Celebrity { String name; String description; Each Object Has Its Own Instance Fields You declare the instance fields once, but each object gets its own copies??? //...declare methods, too... Each Object Has Its Own Instance Fields You declare the instance fields once, but each object gets its own copies??? Remember: the class is like a blueprint or pattern. It says how to make objects: A car blueprint shows a steering wheel, but each car gets its own steering wheel. A dress pattern shows one pocket, but each dress has its own pocket. Celebrity class shows String variables for name and description, but each object gets its own. Accessing Instance Fields If the instance fields are public, users of the class can treat them like normal variables: prof.name = Alan ; prof.description = dignified ; (If you say neither public nor private, the default is called package access, which is basically public for our purposes.) Keep Instance Fields Private! If the instance fields are public, users of the class can treat them like normal variables: prof.name = Alan ; prof.description = dignified ; If the instance fields are public, users of the class can misuse or mess up your instance fields! Good style is to keep them private. Keep Instance Fields Private! Good style is to keep them private. If the instance fields are private, users of the class can t access them. How do they use your class? 10

11 Accessor and Mutator Methods Questions? Good style is to keep them private. If the instance fields are private, users of the class can t access them. How do they use your class? The standard Java convention is to provide public methods to access (read) or mutate (modify) the instance fields. E.g., getname() or setname(string name) You can control access to fields this way. Constructors What happens if the user forgets to set the instance fields? Constructors What happens if the user forgets to set the instance fields? It s best to supply a default for instance fields at the moment the object is created. This way, all objects are always properly created. We do this by writing our own code for the constructor methods. Constructors To create a constructor method, declare a method with: the same name as the class no return type (at all, not even void) parameters, if you want Put code in the method to initialize the instance fields. Constructors public Celebrity() { this.name = Joe Schmoe"; this.description = forgettable"; this.salary = new BigInteger( 0 ); 11

12 Constructors public Celebrity() { name = Joe Schmoe"; description = forgettable"; salary = new BigInteger( 0 ); Using vs. Designing Classes Using a Class Read API. Get and use objects. Instantiate objects with new ClassName() Call methods to get things done. Access public things only. Designing a Class Write API. Provide blueprint/pattern for objects. Define constructor ClassName() { Implement methods. Say how to actually do things. Decide what is public and what is private. Questions? 12

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Errors (Using the Scanner and String Classes) Anatomy of a Java Program Readings This Week s Reading: Ch 3.1-3.8 (Major conceptual

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Instance Variables if Statements Readings This Week s Reading: Review Ch 1-4 (that were previously assigned) (Reminder: Readings

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu (Using the Scanner and String Classes) Anatomy of a Java Program Readings This Week s Reading: Ch 3.1-3.8 (Major conceptual jump

More information

Using Classes and Objects. Lecture 7. Midterms Save the Dates! Extra Credit Survey

Using Classes and Objects. Lecture 7. Midterms Save the Dates! Extra Credit Survey University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.6-2.10, Finish Ch 4 Using Classes and Objects Lecture 7 Some

More information

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static.

Survey #2. Variable Scope. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Scope Static. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Scope Static Readings This Week: Ch 8.3-8.8 and into Ch 9.1-9.3 (Ch 9.3-9.8 and Ch 11.1-11.3 in old 2 nd ed) (Reminder: Readings

More information

PeerWise Study. Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Constants Using Classes and Objects

PeerWise Study. Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Constants Using Classes and Objects University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Constants Using Classes and Objects Lecture 4 Some slides borrowed from Kurt Eiselt, Tamara Munzner, and Steve Wolfman. Some learning

More information

Survey #2. Teen Talk Barbie TM Reloaded. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists

Survey #2. Teen Talk Barbie TM Reloaded. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Partially Filled Arrays ArrayLists Do-It-Yourself ArrayLists Scope Static Readings This Week: Ch 8.3-8.8 and into Ch 9.1-9.3 (Ch

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu if Statements Designing Classes Abstraction and Encapsulation Readings This Week s Reading: Review Ch 1-4 (that were previously

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Primitive Data Types Arithmetic Operators Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch 4.1-4.2.

More information

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Arithmetic Operators Type Conversion Constants Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Arithmetic Operators Type Conversion Constants Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

Survey #2. Programming Assignment 3. Final Exam. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Accessing the Superclass Object Hierarchies is-a, has-a Readings This Week: Ch 9.4-9.5 and into Ch 10.1-10.8 (Ch 11.4-11.5 and into

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Abstraction and Encapsulation javadoc More About if Statements Readings This Week: Ch 5.1-5.4 (Ch 6.1-6.4 in 2 nd ed). (Reminder:

More information

Survey #2. Assignment #3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Static Interface Types.

Survey #2. Assignment #3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. Static Interface Types. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Static Interface Types Lecture 19 Readings This Week: Ch 8.3-8.8 and into Ch 9.1-9.3 (Ch 9.3-9.8 and Ch 11.1-11.3 in old 2 nd ed)

More information

Survey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Survey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Defining Interfaces Intro to Inheritance Readings This Week: Ch 9.4-9.5 and into Ch 10.1-10.8 (Ch 11.4-11.5 and into Ch 13 in old

More information

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Interfaces vs. Inheritance Abstract Classes Inner Classes Readings This Week: No new readings. Consolidate! (Reminder: Readings

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Abstraction and Encapsulation javadoc More About if Statements Intro to while Loops Readings This Week: Ch 5.1-5.4 (Ch 6.1-6.4 in

More information

Last Week: Organizing Data. Last Week: Parallel Arrays. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.

Last Week: Organizing Data. Last Week: Parallel Arrays. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Arrays of/in Objects Partially Filled Arrays ArrayLists Do-It-Yourself ArrayLists Readings Next Week: Ch 8.3-8.8 and into Ch 9.1-9.3

More information

Classes. Classes as Code Libraries. Classes as Data Structures

Classes. Classes as Code Libraries. Classes as Data Structures Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters)

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters) Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Inheritance II Lecture 23, Thu Mar 30 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr

More information

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Conditionals II Lecture 11, Thu Feb 9 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

1B1b Classes in Java Part I

1B1b Classes in Java Part I 1B1b Classes in Java Part I Agenda Defining simple classes. Instance variables and methods. Objects. Object references. 1 2 Reading You should be reading: Part I chapters 6,9,10 And browsing: Part IV chapter

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com CHAPTER 8 OBJECTS AND CLASSES Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/2011 Chapter Goals To understand the concepts of classes, objects and encapsulation To implement instance variables,

More information

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100 Department of Computer Science Undergraduate Events Events this week Drop-In Resume Edition Date: Mon. Jan 11 Time: 11 am 2 pm Location: Rm 255, ICICS/CS Industry Panel Speakers: Managers from IBM, Microsoft,

More information

Survey #3. Final Exam. Today is totally optional! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings.

Survey #3. Final Exam. Today is totally optional! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Readings This Week: No new readings. Consolidate! (Reminder: Readings are absolutely vital for learning this stuff!) Multithreading

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics

More information

! labs last week. ! still time to work through lab 7 (midterm correction) ! can earn back up to 5 out of 70 points

! labs last week. ! still time to work through lab 7 (midterm correction) ! can earn back up to 5 out of 70 points University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Interfaces, Inheritance Lecture 22, Tue Mar 28 2006! labs last week News! still time to work through lab 7 (midterm

More information

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques 1 CPSC2620 Advanced Programming Spring 2003 Instructor: Dr. Shahadat Hossain 2 Today s Agenda Administrative Matters Course Information Introduction to Programming Techniques 3 Course Assessment Lectures:

More information

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Static Methods, Conditionals Lecture 10, Tue Feb 7 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr

More information

Express Yourself. Writing Your Own Classes

Express Yourself. Writing Your Own Classes Java Programming 1 Lecture 5 Defining Classes Creating your Own Classes Express Yourself Use OpenOffice Writer to create a new document Save the file as LastFirst_ic05 Replace LastFirst with your actual

More information

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG CS 121 Intro to Programming:Java - Lecture 2 Course home page: Professor Robert Moll (+ TAs) CS BLDG 276-545-4315 moll@cs.umass.edu http://twiki-edlab.cs.umass.edu/bin/view/moll121/webhome First OWL assignment

More information

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

! Midterm 2: Thu Mar 16, 6:30pm (TODAY!) ! Woodward 2. ! hour-long exam, reserve 6:30-8 time slot. ! no labs/tutorials this week. ! Bunny.

! Midterm 2: Thu Mar 16, 6:30pm (TODAY!) ! Woodward 2. ! hour-long exam, reserve 6:30-8 time slot. ! no labs/tutorials this week. ! Bunny. University of British Columbia CPSC 111, Intro to Computation Jan-Apr 26 Tamara Munzner Advanced Class Design Lecture 19, Thu Mar 16 26 News! Midterm 2: Thu Mar 16, 6:3pm (TODAY!)! Woodward 2! hour-long

More information

Introduction to Objects. James Brucker

Introduction to Objects. James Brucker Introduction to Objects James Brucker What is an Object? An object is a program element that encapsulates both data and behavior. An object contains both data and methods that operate on the data. Objects

More information

CS 151. Exceptions & Javadoc. slides available on course website. Sunday, September 9, 12

CS 151. Exceptions & Javadoc. slides available on course website. Sunday, September 9, 12 CS 151 Exceptions & Javadoc slides available on course website 1 Announcements Prelab 1 is due now. Please place it in the appropriate (Mon vs. Tues) box. Please attend lab this week. There may be a lecture

More information

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG CS 121 Intro to Programming:Java - Lecture 2 Course home page: Professor Robert Moll (+ TAs) CS BLDG 276-545-4315 moll@cs.umass.edu http://twiki-edlab.cs.umass.edu/bin/view/moll121/webhome Read text chapters

More information

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015 COMP-202: Foundations of Programming Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015 Assignment Due Date Assignment 1 is now due on Tuesday, Jan 20 th, 11:59pm. Quiz 1 is

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 7: Construction of a Simulated Cash Register and a Student Class 28 February 2019 SP1-Lab7-2018-19.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Coursework Plagiarism Plagiarism

More information

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS121/IS223. Object Reference Variables. Dr Olly Gotel CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223

More information

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB A reminder about Labs Announcements Please make sure you READ

More information

Exploring the Java API, Packages & Collections

Exploring the Java API, Packages & Collections 6.092 - Introduction to Software Engineering in Java Lecture 7: Exploring the Java API, Packages & Collections Tuesday, January 29 IAP 2008 Cite as: Evan Jones, Olivier Koch, and Usman Akeju, course materials

More information

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want

More information

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7 Administration Classes CS 99 Summer 2000 Michael Clarkson Lecture 7 Lab 7 due tomorrow Question: Lab 6.equals( SquareRoot )? Lab 8 posted today Prelim 2 in six days! Covers two weeks of material: lectures

More information

This Week. Fields and Variables. W05 Example 1: Variables & Fields. More on Java classes. Constructors. Modifiers

This Week. Fields and Variables. W05 Example 1: Variables & Fields. More on Java classes. Constructors. Modifiers This Week More on Java classes School of Computer Science University of St Andrews Graham Kirby Alan Dearle Constructors Modifiers cdn.videogum.com/img/thumbnails/photos/commenter.jpg http://www.rodgersleask.co.uk/images/sc2.jpg

More information

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java 1 CS/ENGRD 2110 FALL 2017 Lecture 2: Objects and classes in Java http://courses.cs.cornell.edu/cs2110 CMS VideoNote.com, PPT slides, DrJava 2 CMS. Visit course webpage, click Links, then CMS for 2110.

More information

Midterms Save the Dates!

Midterms Save the Dates! Unversty of Brtsh Columba CPSC, Intro to Computaton Alan J. Hu Readngs Ths Week: Ch 6 (Ch 7 n old 2 nd ed). (Remnder: Readngs are absolutely vtal for learnng ths stuff!) Thnkng About Loops Lecture 9 Some

More information

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation Anatomy of a Method September 15, 2006 HW3 is due Today ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Midterm 1 Next Tuesday Sep 19 @ 6:30 7:45pm. Location:

More information

University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner

University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner Inheritance II Lecture 34, Mon Apr 12 2010 borrowing from slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/111-10

More information

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented

More information

! This week: Chapter 6 all ( ) ! Formal parameter: in declaration of class. ! Actual parameter: passed in when method is called

! This week: Chapter 6 all ( ) ! Formal parameter: in declaration of class. ! Actual parameter: passed in when method is called University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Reading! This week: Chapter 6 all (6.1-6.4) Static Methods, Conditionals Lecture 10, Tue Feb 7 2006 based on slides

More information

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple movie data system. Milestones: 1. Use

More information

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit. Com S 227 Fall 2018 Miniassignment 1 40 points Due Date: Friday, October 12, 11:59 pm (midnight) Late deadline (25% penalty): Monday, October 15, 11:59 pm General information This assignment is to be done

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 7: Construction of a Simulated Cash Register and a Student Class 22 February 2018 SP1-Lab7-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Coursework Plagiarism Plagiarism is

More information

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

Java Basics Lecture: January 26, 2012 (On-line Lecture 1) Java Basics Lecture: January 26, 2012 (On-line Lecture 1) CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers Prof. Erik Learned-Miller Logistics Previous lectures are on-line. See links

More information

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple magazine data system. Milestones:

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 80 points Due Date: Friday, February 2, 11:59 pm (midnight) Late deadline (25% penalty): Monday, February 5, 11:59 pm General information This assignment is to be done

More information

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009 CMPT 117: Tutorial 1 Craig Thompson 12 January 2009 Administrivia Coding habits OOP Header Files Function Overloading Class info Tutorials Review of course material additional examples Q&A Labs Work on

More information

Readings for This Lecture

Readings for This Lecture Lecture 4 Classes Readings for This Lecture Section 1.4, 1.5 in text Section 3.1 in text Plive activities referenced in the text Please look at lecture summaries online Handouts are short version Presentation

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit. Com S 227 Spring 2018 Miniassignment 1 40 points Due Date: Thursday, March 8, 11:59 pm (midnight) Late deadline (25% penalty): Friday, March 9, 11:59 pm General information This assignment is to be done

More information

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction

More information

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Objects, Methods, Parameters, Input Lecture 5, Thu Jan 19 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Data Abstraction January 25, 2010 Prof. Chris Clifton Announcements Book is available (Draft 2.0) Syllabus updated with readings corresponding to new edition Lab consulting hours

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Arrays, Part 1 of 2 Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Arrays, Part 1 of 2 1 / 14 Modeling Aggregates As you ve seen, you

More information

Fundamentos de programação

Fundamentos de programação Fundamentos de programação Orientação a Objeto Classes, atributos e métodos Edson Moreno edson.moreno@pucrs.br http://www.inf.pucrs.br/~emoreno Contents Object-Oriented Programming Implementing a Simple

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

Final Exam Practice. Partial credit will be awarded.

Final Exam Practice. Partial credit will be awarded. Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the

More information

Chapter 6 Lab Classes and Objects

Chapter 6 Lab Classes and Objects Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value

More information

Lab 1: Introduction to Java

Lab 1: Introduction to Java Lab 1: Introduction to Java Welcome to the first CS15 lab! In the reading, we went over objects, methods, parameters and how to put all of these things together into Java classes. It's perfectly okay if

More information

Chapter Two Bonus Lesson: JavaDoc

Chapter Two Bonus Lesson: JavaDoc We ve already talked about adding simple comments to your source code. The JDK actually supports more meaningful comments as well. If you add specially-formatted comments, you can then use a tool called

More information

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.

CISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing. CISC-124 20180115 20180116 20180118 We continued our introductory exploration of Java and object-oriented programming by looking at a program that uses two classes. We created a Java file Dog.java and

More information

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 3 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay Computer Science and Engineering Indian Institue of Technology Bombay November 27, 2004 What is Object Oriented Programming? Identifying objects and assigning responsibilities to these objects. Objects

More information

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces. Com S 227 Fall 2016 Topics and review problems for Exam 2 Thursday, November 10, 6:45 pm Locations, by last name: (same locations as Exam 1) A-C Curtiss 0127, first floor only D-N Hoover 2055 O-Z Troxel

More information

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects Administrative Stuff September 12, 2007 HW3 is due on Friday No new HW will be out this week Next Tuesday we will have Midterm 1: Sep 18 @ 6:30 7:45pm. Location: Curtiss Hall 127 (classroom) On Monday

More information

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment 60-212 subir@cs.uwindsor.ca Phone # 253-3000 Ext. 2999 web site for course www.cs.uwindsor.ca/60-212 Dr. Subir Bandyopadhayay Website has detailed rules and regulations All assignments and labs will be

More information

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public

More information

BM214E Object Oriented Programming Lecture 8

BM214E Object Oriented Programming Lecture 8 BM214E Object Oriented Programming Lecture 8 Instance vs. Class Declarations Instance vs. Class Declarations Don t be fooled. Just because a variable might be declared as a field within a class that does

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Machine vs. High-Level Languages Interpreters and Compilers Writing a Simple Java Program Readings Your textbook is Big Java (3rd

More information

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class? Administration Objects and Arrays CS 99 Summer 2000 Michael Clarkson Lecture 6 Read clarified grading policies Lab 6 due tomorrow Submit.java files in a folder named Lab6 Lab 7 Posted today Upson Lab closed

More information

Object-Oriented Programming in Processing

Object-Oriented Programming in Processing Object-Oriented Programming in Processing Object-Oriented Programming We ve (kinda) been doing this since Day 1: Python is a deeply object oriented language Most of the data types we were using (strings,

More information

Week 7 - More Java! this stands for the calling object:

Week 7 - More Java! this stands for the calling object: Week 7 - More Java! Variable Scoping, Revisited this Parameter Encapsulation & Principles of Information Hiding: Use of public and private within class API, ADT javadoc Variables of class Type Wrapper

More information

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Objects and Classes (contd.) Course Lecture Slides 19 May 2010 Ganesh Viswanathan Objects and Classes Credits: Adapted from CIS3023 lecture

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

EECS168 Exam 3 Review

EECS168 Exam 3 Review EECS168 Exam 3 Review Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any

More information

Lecture 02, Fall 2018 Friday September 7

Lecture 02, Fall 2018 Friday September 7 Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

More information

Agenda: Notes on Chapter 3. Create a class with constructors and methods.

Agenda: Notes on Chapter 3. Create a class with constructors and methods. Bell Work 9/19/16: How would you call the default constructor for a class called BankAccount? Agenda: Notes on Chapter 3. Create a class with constructors and methods. Objectives: To become familiar with

More information

Exam Percentage: / 55 = %

Exam Percentage: / 55 = % 1/6 CS 1316 - Exam 1 - Spring 2010 Name: CS 1316 - Exam 1 - Spring 2010 Your Grading TA: Your Section : INTEGRITY: By taking this exam, you pledge that this is your work and you have neither given nor

More information