Copyright by Scott GrissomCh 4 Grouping Objects Slide 1 Flexible-size Collections flexible collection of objects unlimited and unknown size iPod playlist.

Slides:



Advertisements
Similar presentations
A Short Review Arrays, Pointers and Structures. What is an Array? An array is a collection of variables of the same type and placed in memory contiguously.
Advertisements

Why not just use Arrays? Java ArrayLists.
Copyright © 2002 Pearson Education, Inc. Slide 1.
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;
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Grouping Objects Arrays and for loops. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Fixed-Size Collections.
Using Collections. Review of Collections Using an ArrayList It increases its capacity as necessary. It keeps a private count ( size() accessor). It keeps.
Programming with Collections Collections in Java Using Arrays Week 9.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Grouping objects Collections and iterators. 04/11/2004Lecture 4: Grouping Objects2 Main concepts to be covered Collections Loops Iterators Arrays.
Chapter 9 Introduction to Arrays
Programming with Collections Grouping & Looping - Collections and Iteration Week 7.
Arrays.
Chapter 101 Dynamic Data Structures and Generics Chapter 10.
Chapter 8 ARRAYS Continued
Writing Methods Using if, loops, and variables to implement algorithms Copyright © 2012 Pearson Education, Inc.
Grouping objects Collections and iterators. Main concepts to be covered Collections Loops Iterators.
Iteration and Simple Menus Deterministic / Non-deterministic loops and simple menus.
AP CS Workshop ArrayList It is very common for applications to require us to store a large amount of data. Array lists store large amounts of data.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0.
Grouping objects Arrays, Collections and Iterators 1.0.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
© 2007 Lawrenceville Press Slide 1 Chapter 10 Arrays  Can store many of the same kind of data together  Allows a collection of related values to be stored.
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 BUILDING JAVA PROGRAMS CHAPTER 7.1 ARRAY BASICS.
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Enhanced For Loops (For Each Loops) Less Code and Less Overhead for Writing For Loops.
JAVA COLLECTIONS M. TAIMOOR KHAN (ADAPTED FROM SWINBURNE NOTES)
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Grouping objects Iterators. Iterator type Third variation to iterate over a collection Uses a while loop and Iterator object But NO integer index variable.
Copyright by Scott GrissomCh 2 Class Definition Slide 1 Class Structure public class BankAccount{ fields constructor(s) methods } Sample Code Ticket Machine.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 1.0.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3,
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
1 BUILDING JAVA PROGRAMS CHAPTER 7.2 ARRAY TRAVERSAL ALGORITHMS.
Arrays. Array: Sequence of values of the same type Construct array: Store in variable of type double[ ] new double[10] double[] data = new double[10];
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Grouping objects Arrays. 2 Fixed-size collections The maximum collection size may be pre-determined with an upper limit Array is an fixed-size collection.
Programming Fundamentals 2: Grouping/ F II Objectives – –discuss call-by-value and call-by-reference, arrays, collections, and iterators.
Jeopardy Print Me Which loop? Call Me Name Me My Mistake Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Chapter 6 Arrays 1 Fall 2012 CS2302: Programming Principles.
Comparing ArrayLists and Arrays. ArrayLists ArrayLists are one type of flexible-size collection classes supported by Java –ArrayLists increase and decrease.
Copyright © Texas Education Agency, Advanced Computer Programming Data Structures: Basics.
Collections and Iteration Week 13.  Collections  ArrayList objects  Using loops with collections Collections and Iteration CONCEPTS COVERED THIS WEEK.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Basic arrays, binary search, selection sort by amelia bateman
Lecture 5 D&D Chapter 6 Arrays and ArrayLists Date.
Chapter 7: Array.
Can store many of the same kind of data together
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
ArrayLists.
Can store many of the same kind of data together
Object-Oriented Programming Paradigm
Collections and iterators
Can store many of the same kind of data together
Programming Control Structures with JavaScript Part 2
Loops and Arrays in JavaScript
Collections and iterators
Tuple.
Presentation transcript:

copyright by Scott GrissomCh 4 Grouping Objects Slide 1 Flexible-size Collections flexible collection of objects unlimited and unknown size iPod playlist as an example ArrayList provided in java.util.*; ArrayList playList; playList = new ArrayList (); Methods add(Object) // to end of list int size () Object get (int index) Object remove (int index) first item is in location zero Draw object diagram

copyright by Scott GrissomCh 4 Grouping Objects Slide 2 Processing Elements Cumbersome playList.get(0).play(); playList.get(1).play(); playList.get(2).play(); We need a flexible way to access each element even though we do not know how many For-each loop process each item in order until done for (Song s : playList){ s.play(); }

copyright by Scott GrissomCh 4 Grouping Objects Slide 3 Group Activity ArrayList stuff; Stuff = new ArrayList (); Stuff.add(“Howdy!”); Stuff.add(“My Name “); stuff.add(“is “); stuff.add(“Ralph”); stuff.remove(2); for(String str : stuff){ System.out.println(str); }

copyright by Scott GrissomCh 4 Grouping Objects Slide 4 While loop an alternative repetition structure int x = 0; while (x < 10){ System.out.println(x); } Advantages no collection required every element does not have to be processed Example Notebook search (p 94) Group exercises

copyright by Scott GrissomCh 4 Grouping Objects Slide 5 Auction System (4.10) Multiple classes Person contains a name Bid contains a value and Person Lot a description, lot #, high bid review the bidFor method Auction page 99 an ArrayList of logs and nextLotNumber review the bidFor method Group activities write additional methods 4.26 close 4.27 getUnsold() 4.30 removeLot()

copyright by Scott GrissomCh 4 Grouping Objects Slide 6 Fixed-size Collections called an array able to store objects or primitive types first element at location 0 uses a different syntax than ArrayList int [ ] nums; nums = new int [10]; used just as a variable nums[3] = 100; x = 5; nums[x] = 7; value = nums[x] + 8;

copyright by Scott GrissomCh 4 Grouping Objects Slide 7 for loop different syntax than for-each three parts for (int i = 0; i < 20; i++) System.out.println(i); for(index = 0; index < array.length; index++) total = total + array[index]; Group Activities sum average max min find

copyright by Scott GrissomCh 4 Grouping Objects Slide 8 Which loop? most are interchangeable while number of iterations is determined during performance for number of iterations is know before loop begins for-each process all elements of a collection