Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Slides:



Advertisements
Similar presentations
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Advertisements

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSE 113 Introduction to Computer Programming Lecture slides for Week 6 Monday, October 3 rd, 2011 Instructor: Scott Settembre.
Economics 1 Principles of Microeconomics Instructor: Ted Bergstrom.
Arrays Recitation – 10/(9,10)/2008 CS 180 Department of Computer Science, Purdue University.
CSSE221: Software Dev. Honors Day 28 Announcements Announcements Simulation grades coming back Simulation grades coming back All C Projects due Friday.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
© 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not be copied or used for any.
Copywrite 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not be copied or used.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 More Class Design III, Parameter/Scope Review Lecture.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Please open Daily Quiz 34. A scientific calculator may be used on this quiz. You can keep your yellow formula sheets out when you take the quiz. Remember.
6-1 Object-Oriented Design Today we focuses on: –the this reference (Chapter 7) –the static modifier (Chapter 7) –method overloading (Chapter 7)
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
CSE8A Lecture3 TODO: –Finish PSA1 individually (no partner!) and turn it in with the bundlePSA1 command GET AN INTERVIEW for PSA1 from a tutor See tutor.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSE8A Lecture2 Check the class web page (and discussion board, linked form webpage) for news and info: cse8a.weebly.com Lab starts this week. Discussion.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 2/10/2010.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Lecture 5 Announcements. HW2 – Regrading Thinking like a programmer –Part b: (5 points) Test for input in the range it is specified (otherwise what is.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Coming Up: Today: Review Quiz 2 Lecture on Section 2.4: Word problems! NOTE: This homework is due at the beginning of the next class session. Coming up.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSE8A: Introduction to Programming in Java Fall 2012 Prof. Christine Alvarado cse8afall.weebly.com.
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.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 22: Pointers.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Week 8 - Friday.  What did we talk about last time?  Static methods.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
1 CS September 2008 Discussion of Methods: Executing method calls.If-statements. The return statement in a function. Local variables. For this and.
Today’s lecture Review chapter 5 go over exercises.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Non-Static Classes What is the Object of this lecture?
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
COMP 110 More arrays, 2D arrays, Program 4 Luv Kohli November 10, 2008 MWF 2-2:50 pm Sitterson 014.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Coming Up: Today: Review Quiz 2 Lecture on Section 2.4: Word problems! NOTE: This homework is due at the beginning of the next class session. Coming up.
REMINDER: If you haven’t yet passed the Gateway Quiz, make sure you take it this week! (You can find more practice quizzes online in the Gateway Info menu.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Creative Commons Attribution Non-Commercial Share Alike License
CSE 116/504 – Intro. To Computer Science for Majors II
Lecture 11 C Parameters Richard Gesick.
Variables and Their scope
Code Animation Examples
Chapter 4 Topics: class declarations method declarations
Creative Commons Attribution Non-Commercial Share Alike License
Creative Commons Attribution Non-Commercial Share Alike License
Creative Commons Attribution Non-Commercial Share Alike License
Lecture 8-2: Object Behavior (Methods) and Constructors
Presentation transcript:

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/ sa/3.0/ Original Developer: Beth Simon, 2009

CSE8A Lecture 27 Read next class: Re-read Chapter 2 PSA9 due WED 11:59pm (pair – Make a class for Participant in medical study) Exam: Wed 3-6pm –Individual and Group –Survey Linked from Moodle under sample exam (up by Friday 5pm) Study CLICKER QUESTIONS (and quizzes, labs, PSAs, practice writing code) –Review Session Friday: –Quiz (more points for you, practice for final) –TA evals –Microsoft Filming… If you don’t want to be filmed, let your group know, sit in roped off area

Lab 4: Grades will be assigned as average if missing: Who is missing… (vote A for each lab, multiple votes) Lab 3 Lab 5 Lab 6 Lab 8 (week 8, lab 7)

CSE8A Art Exhibition!!! Honorable Mention

CSE 8A Art Exhibition Grand Prize

When can you make review session? (just vote A when I call that time, we’ll do multiple votes) Monday Monday 12-1 Monday 3-4 Tuesday Tuesday 12-1 Tuesday 3-4

By the end of today’s class you should be able to… LLG54: Be able to draw the memory model of an object (at a more detailed level than before) – based on what happens in a constructor. LG55: Identify legal and illegal instances of method overloading, so you can know what “variations” on methods you can write. LG56: Create arrays of objects of any length or type and be able to use good software design for using arrays as fields

Our Species class example public class Species { ///////// fields //////////// private String name; private int[] population; private double growthRate; /////// constructors /////////// /////// methods //////////////// }

Review: Draw what happens here… (hint pg 357) public Species(String newName, int[] newPop, double newGR) { name = newName; for (int i=0; i< this.population.length;i++) population[i] = newPop[i]; growthRate = newGR; } DO YOU UNDERSTAND? There’s a missing line that causes an error – what is it?

Review: Keeping our data secure (pg 356 is insecure) public Species(String newName, int[] newPop, double newGR) { name = newName; population = new int[newPop.length]; for (int i=0; i< this.population.length;i++) population[i] = newPop[i]; growthRate = newGR; } public Species(String newName, int[] newPop, double newGR) { name = newName; //BAD DESIGN… INSECURE population = newPop; growthRate = newGR; }

Why? Remember there is a main program that sent in “newPop” public static void main LabX(String[] args) { int[] mypop = {30,455,2,0,6376}; Species s = new Species(“Naked Mole Rat”, mypop, 3.3); } public Species(String newName, int[] newPop, double newGR) { name = newName; //BAD DESIGN… INSECURE population = newPop; growthRate = newGR; }

Which is more secure?

Modifying the Species class This idea that the population array is just 5 entries, one per continent is a bit “obscure”. What if we have 2 arrays that are “linked” from a design point of view. –One keeps the name of the “place” –One keeps the population of the animal in that “place” What would my instance variables be?

Write a constructor for the new Species class public Species(String newName, int[] newPop, String[] location, double newGR) { name = newName; population = new int[newPop.length]; for (int i=0; i< this.population.length;i++) population[i] = newPop[i]; > growthRate = newGR; } location = location; this.location = location; location = new String[location.length]; for (int i=0; i < location.length; i++) location[i] = location[i]; location = new String[location.length]; for (int i=0; i < location.length; i++) this.location[i] = location[i];

Write a constructor for the new Species class Still has some “bad software design issues…” public Species(String newName, int[] newPop, String[] location, double newGR) { name = newName; population = new int[newPop.length]; for (int i=0; i< this.population.length;i++) population[i] = newPop[i]; location = new String[location.length]; for (int i=0; i < location.length; i++) this.location[i] = location[i]; growthRate = newGR; }

public Species(String newName, int[] newPop, String[] location, double newGR) { name = newName; growthRate = newGR; if (newPop.length != location.length) { System.out.println(“Error constructing Species. “+ “Population array and location array must be same length.”); population = null; location = null; return; } population = new int[newPop.length]; location = new String[location.length]; for (int i=0; i < location.length; i++) { this.location[i] = location[i]; this.population[i] = newPop[i]; } What is this code doing? A)Making sure newPop and location are legal B)Making sure newPop and location are of the same length C)Setting population and location to null D)Error, return without variable