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

Slides:



Advertisements
Similar presentations
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
For use of IST410 Students only Arrays-1 Arrays. For use of IST410 Students only Arrays-2 Objectives l Declaring arrays l Instantiating arrays l Using.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 03 / 2008 Instructor: Michael Eckmann.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
Games and Simulations O-O Programming in Java The Walker School
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Lec 19 Array Intro. Agenda Arrays—what are they Declaring Arrays Constructing Arrays Accessing Array cells.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
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/
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Chapter 8: Arrays.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
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/
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.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
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/
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
CMSC 202 Arrays 2 nd Lecture. Aug 6, Array Parameters Both array indexed variables and entire arrays can be used as arguments to methods –An indexed.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Chapter 7 – Arrays and Array Lists Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. 1.
Java – An Object Oriented Language CS 307 Lecture Notes Lecture Weeks 5-6 Khalid Siddiqui.
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
CSE 8A Lecture 14 Reading for next class: None (INTERM EXAM #3) Today’s topics: –More Sounds! PSA 6 due tonight PSA 7 (sounds) due next Monday (11/19)
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
02/09/2005 Introduction to Programming with Java, for Beginners Arrays (of primitives)
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Introduction to programming in java Lecture 21 Arrays – Part 1.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Creative Commons Attribution Non-Commercial Share Alike License
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Creative Commons Attribution Non-Commercial Share Alike License
Building Java Programs
Creative Commons Attribution Non-Commercial Share Alike License
Creative Commons Attribution Non-Commercial Share Alike License
Java Programming Language
Data Structures & Algorithms
Presentation transcript:

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

CSE8A Lecture 28 Exam: Wed 3-6pm, Center 119 –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: Monday 3-4pm Filming Today –If you or someone in your group doesn’t want to be “a face in the crowd”, move into taped off area –If you answer question in class – we won’t be using your voice SO DON’T BE SHY!!!!

By the end of today’s class you should be able to… LG56: Create arrays of objects of any length or type and be able to use good software design for using arrays as fields LG57: Apply your Picture and Sound knowledge of arrays to general usage of arrays LG58: Evaluate expressions reflecting the fact that array variables in Java refer to a location in memory where that data is stored. LG59: Describe necessary code structures required to perform specific tasks on arrays.

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

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]; } Review: 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

Designing a class securely… Security of instance variables fields –Data values in a specific field may need to be checked for limited legal value ranges Examples? –Data values BETWEEN instance variables might be limited/constrained Example (date) –Arrays may need to be checked for length / correlation with each other

A possible setter method public boolean changePopulation(int pop, String loc) { if (pop < 0) return false; > } location[0] = pop;location[location.length] = pop; for (int i=0; i<loc.length; i++) { if (location[i].equals(loc)) population[i] = pop; } for (int i=0; i<pop.length; i++) { if (population[i] == pop) location[i] = pop; }

Arrays in Java Not just for Pixels anymore…

How many of the following statements are true? A particular “instance” of an array can “hold” objects of different types: An array of Species objects of length 10 MUST have 10 references to Species objects stored in it An array of Species objects of length 10 has SOME value (possibly null) in each of its cells An array instantiated with 10 items can be changed to hold 11 items if needed

Which of the following evaluates to true about the code snippet below? int[] foo = {33,22,11}; int[] bar = {33,22,11}; foo == bar; foo.equals(bar); bar.equals(foo); foo != bar; It depends on how memory is allocated…

Question (that we don’t have to answer) : How many people in the class scored above the average grade for the class? –Hint it’s not always N/2

How many loops would be needed to count the number of array elements above the average of the values in the array? (assuming you don’t already know the average) A.1 loop B.2 loops, one after the other C.2 nested loops D.3 loops, one after the other