Review Objects – data fields – constructors – Methods Classes.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Introduction to C Programming
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Lesson Four: More of the Same
OO Programming Objectives for today: Casting Objects Introduction to Vectors The instanceof keyword.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
 9: Arrays  Why?  What is an Array?  Declaring and Creating an Array  Initializing and Array  Array Operations  Array Examples  Arrays of Objects.
Arrays.
Introduction to arrays Data in economy size packages.
 2003 Prentice Hall, Inc. All rights reserved. 7.1 Introduction Arrays –Data structures which reference one or more value –All items must have same data.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Java Syntax Primitive data types Operators Control statements.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
 2003 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Arrays Introduction to Computers and Programming in.
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Arrays & Linked Lists Last Update: Aug 21, 2014EECS2011: Arrays & Linked Lists1.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Great Video Game Crash of Napoleon’s Russian Campaign,
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Chapter 8: Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Built-in Data Structures in Python An Introduction.
Arrays Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Applications Development
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Arrays. An array is a collection “The Dinner offers an array of choices.” In computer programming, an array is a collection of variables of the same data.
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
SORTING Chapter 8 CS Chapter Objectives  To learn how to use the standard sorting methods in the Java API  To learn how to implement the following.
Arrays1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
Computer Science I Arrays. Parallel structures. Classwork/Homework: Build your own bouncing things.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Welcome back!. Object Oriented Programming – Encapsulation Classes encapsulate state (fields) and behavior (methods) – Polymorphism Signature Polymorphism.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Review Array – int[] diameters = new int[10]; – diameters[0], diameters[2], diameters[9] – diameters.length Indexing starts at 0 A way to have a collection.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
Chapter 8 Slides from GaddisText Arrays of more than 1 dimension.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
The ArrayList Data Structure The Most Important Things to Review.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
Arrays. 2 Why do we care (about arrays)? What if you have a whole bunch of cars (or aliens or balls or ???) bouncing around the screen? How do we keep.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Functions. 2 Modularity What is a function? A named block of code Sometimes called a ‘module’, ‘method’ or a ‘procedure’ Some examples that you know are:
Arrays Chapter 7.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Containers and Lists CIS 40 – Introduction to Programming in Python
Chapter 8 Objects.
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Chapter 8 Slides from GaddisText
Data Structures – 1D Lists
Object Oriented Programming in java
String and Lists Dr. José M. Reyes Álamo.
Chapter 8 Objects.
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Chapter 4, Variables Brief Notes
Python List.
Presentation transcript:

Review Objects – data fields – constructors – Methods Classes

Arrays A special kind of variable that holds not one, by many data items of a given type. Declared like variables, only type is followed by a pair of brackets. float[] xs; Can be initialized using a special syntax involving the new keyword, the type, and a size in brackets. int[] diameters = new int[10]; // Ten diameters

Arrays Individual data items are accessed with an index and square brackets. – diameters[0], diameters[1], etc – Indexes start at 0! The length of an array can be determined using its length property. – diameters.length – The length of an array is one greater than the last valid index. Arrays can be passed to, and returned from functions.

int[] diameters = new int[10]; void setup() { size(500, 500); background(200); for (int i=0; i<diameters.length; i++) { diameters[i] = int(random(0, width/2)); } fill(255, 0, 0); for (int i=0; i<diameters.length; i++) { ellipse(random(width), random(height), diameters[i], diameters[i]); } void draw() { }

Use the Ball class Ball[] balls = new Ball[20]; void setup() { size(500, 500); fill(255, 0, 0); smooth(); ellipseMode(CENTER); // Create all new Ball objects for (int i = 0; i < balls.length; i++) { balls[i] = new Ball(); } void draw() { background(255); for (int i = 0; i < balls.length; i++) { balls[i].update(); balls[i].draw(); } Treat in a manner very similar to a primitive data type. Declare an array of Balls. New objects are created with the new keyword. Methods of objects stored in the array are accessed using dot-notation.

Built-in Array Functions append( array, item ) – returns a new array expanded by one and add item to end expand( array, newSize ) – returns a new array with size increased to newSize shorten( array ) – returns a new array shortened by one concat( array1, array2 ) – returns a new array that is the concatenation of array1 and array2 subset( array, offset [, length] ) – returns a subset of array starting at offset and proceeding for length (or end) splice( array, value|array2, index ) or – returns a new array with value or array2 inserted at index sort( array ) – returns a new array sorted numerically or alphabetically reverse( array ) – returns a new array with all elements reversed in order

Pop A game that measures your balloon-popping skill. How it should work… – As game runs, randomly placed balloons inflate – When the player pops (clicks on) a balloon, 1 point is earned – Points are added up throughout the game duration – If one click is over top multiple balloons, all balloons pop and multiple points are earned – The game runs for 30 seconds, and then ends