SE1011 Week 8, Class 1 Today Return Half Exam 3 (I have it with me) Object Oriented Programming Details References as arguments Overloaded methods Garbage.

Slides:



Advertisements
Similar presentations
Introduction to Programming Lecture 31. Operator Overloading.
Advertisements

START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.
AAA. Today’s lecture Review of Chapter 6 Go over examples.
Introduction to Java, OO and IDEs ICW Lecture 2 Errol Thompson Room 134.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 9: Pass-by-Value.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Java Classes Using Java Classes Introduction to UML.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
CS2910 Week 1, Class 3 Today Lab 1 – Additional Assignment Working Ahead Primitives in Java SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder.
SE1011 Week 2, Class 3 Today Compiling and running Another example using Scanner Compile-time and Run-time errors Review for exam SE-1011 Slide design:
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
CS2910 Week 1, Class 2 Today Announce Prof. Michael Vieau’s S-341 6p Thurs Wk 2 Assignment for tomorrow Data Encoding, Part 1 Parsing Data Muddiest Point.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 7: Methods & User Input.
Programming in Java CSCI-2220 Object Oriented Programming.
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
CS2910 Week 2, Class 1 Today Data Encoding, Part 1 Parsing Data Python Muddiest Point Lab 2 – Bring text In Class, Thursday: Quiz Week 6, Monday: Midterm.
CS 11 C++ track: lecture 3 Today const and const -correctness operator overloading.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
SE1011 Week 8, Class 3 Today Designing Code SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1.
SE1011 Week 6, Class 1 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) Muddiest Point Next Half Exam: Week 7, Monday SE-1011 Slide.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
SE1011 Week 6, Class 2 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) UML class diagrams Muddiest Point Next Half Exam: Week 7, Monday.
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.
CSE 1201 Object Oriented Programming ArrayList 1.
SE1011 Week 6, Class 2 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) UML class diagrams Muddiest Point Next Half Exam: Week 7, Monday.
SE1011 Week 3, Class 2 Today Sit down by someone you don't know Learn their name Find out who came farther to get to MSOE at the start of the quarter Designing.
SE1011 Week 5, Class 1 Today More Java API tools Packages Object Oriented Programming Muddiest Point Tomorrow: Lab 5 – In-lab demo requirements now up.
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
CE1901 Week 6, Class 3 Week 6 Mini-Exam Review Muddiest Point Timing Diagrams (See this slide and Outcomes on course webpage – link now available)Outcomes.
Chapter 5 Methods 1. Motivations Method : groups statements that perform a function.  Level of abstraction (black box)  Code Reuse – no need to reinvent.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
SE1011 Week 8, Class 2 Today Return Half Exam 3 (I have it with me) Object Oriented Programming Details Null references (as acting objects and arguments)
CS2910 Week 4, Class 1 Today Encoding in Python – Review Quiz – Encoding in Python Introduction to HTTP SE-2811 Slide design: Dr. Mark L. Hornick Content:
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Classes - Intermediate
Today Quiz not yet graded Final report requirements posted More on Multithreading Happens-Before in Java SE-2811 Slide design: Dr. Mark L. Hornick Content:
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
CS2910 Week 8, Class 2 Today Return Quiz Look at Schedule TCP implementation! Week 8, Monday Quiz on SMTP May include some questions requiring you to interpret.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
SE1011 Week 7, Class 3 Today Return Half Exam 3 (I have it with me) Object Oriented Programming Details References as arguments Overloaded methods Garbage.
SE1011 Week 9, Class 3 Today Arrays with Loops! Homework SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1.
Week 6, Class 3: Composite Swing composites File composites Computer composites SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Values vs. References Lecture 13.
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Slide design: Dr. Mark L. Hornick
Defining Your Own Classes Part 1
Arrays and Collections
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Week 4 Lecture-2 Chapter 6 (Methods).
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Slide design: Dr. Mark L. Hornick
Lecture 11 Parameters CSE /26/2018.
Pointers and dynamic objects
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
String Class.
Parameters, Overloading Methods, and Random Garbage
Classes and Objects Object Creation
ITE “A” GROUP 2 ENCAPSULATION.
CMSC 202 Constructors Version 9/10.
Presentation transcript:

SE1011 Week 8, Class 1 Today Return Half Exam 3 (I have it with me) Object Oriented Programming Details References as arguments Overloaded methods Garbage collector again Muddiest Point SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1

Muddiest Point how to specify which objects are used as "this" and "other" reference passing So was the last example an example of why we want the instance variables to be private? So that you can't edit the instances from another class without calling a method?public/private how do objects actually work? object implementation A professor assigned a task worth 1 point. The task was to mix dirt and water. Now that's a muddy point. So was this a lesson on how not to use objects?unused objects what is the significance of the keyword "new" when calling a new instance of a class? What happens if we don't use it?new keyword new diagram type: do we need to learn it? What exactly does each line/shape mean? sequence diagram SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 2

Muddiest Point The diagrams started making sense at the end of the hour. The lifelines especially were a little confusing at firstasequence diagram Using 'this' in constructorsthis how to retrieve the values stored in objects and use them as argumentsaccessor method why wold we call things in this way?reference passing? Why you would want to forget or delete the old class?garbage collection the diagram for the complex driver and user input was not clear to mesequence diagram Is there ever a time we want to write an unused Object?unused objects The new types of diagram seems a bit confusingsequence diagram SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 3

Object Construction new Complex(8,6); // why do this? Complex len5; len5 = new Complex(3,4); SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 4

the multBy method 5 public Complex multBy(Complex other) { // HERE Complex result = new Complex(); result.real = this.real * other.real - this.imag * other.imag; result.imag = this.real * other.imag + this.imag * other.imag; return result; } main(…) Complex real double imag double real Complex ref this Complex(double real, double imag) Complex ref r Complex ref i Complex real double imag double Complex ref other Complex ref prod public static void main(String []) { … // HERE prod = i.multBy(r3); … }

Swapping Methods BUGGY swapping code: int x = 4; int y = 5; x = y; y = x; System.out.println("x: "+x); System.out.println("y: "+y); What does this code print when it is run? Why does it print this? (Can you fix it?) 6

Swapping bacteria in two incubators public void swap(Incubator other) { long temp = this.numBacteria; this.numBacteria = other.numBacteria; other.numBacteria = temp; } SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 7

How to allow both of these this? Complex i = new Complex(0,1); Complex prod1 = i.multBy(3.0); Complex angle45 = new Complex(1,1); Complex prod2 = i.multBy(angle45); sout("result: "+prod1.toString()); // Desired output: "result: i" sout("result: "+prod1.toString()); // Desired output: "result: i" 8

SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 9

Acknowledgement This course is based on the text Introduction to Programming with Java by Dean & Dean, 2 nd Edition SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 10