COS 260 DAY 13 Tony Gauvin.

Slides:



Advertisements
Similar presentations
Grouping objects Iterators. Iterator and iterator() Collections have an iterator() method. This returns an Iterator object. Iterator has three methods:
Advertisements

Grouping objects Arrays and for loops. Fixed-size collections Sometimes the maximum collection size can be pre-determined. Programming languages usually.
Further abstraction techniques Abstract classes and interfaces 5.0.
Grouping Objects Arrays and for loops. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Fixed-Size Collections.
Grouping Objects 3 Iterators, collections and the while loop.
Programming with Collections Collections in Java Using Arrays Week 9.
String Concatenation (operator overloading) 3.0.
Further abstraction techniques Abstract classes and interfaces 3.0.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Understanding class definitions
1 COS 260 DAY 3 Tony Gauvin. 2 Agenda Questions? 1 st Mini quiz on chap1 terms and concepts –Today In BlackBoard –30 min., M/C and short answer, open.
Objects First With Java A Practical Introduction Using BlueJ Supplementary Material for Java
Grouping objects Iterators. Iterator type Third variation to iterate over a collection Uses a while loop and Iterator object But NO integer index variable.
1 COS 260 DAY 19 Tony Gauvin. 2 Agenda Questions? 8 th Mini Quiz not corrected yet 9 Th Mini Quiz next class –Due November 19 Finish Discussion on More.
Testing. Have you contacted your project members lately?
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 1.0.
1 COS 260 DAY 10 Tony Gauvin. 2 Agenda Questions? 4 th Mini quiz Today –Chapter 4 Assignment 2 Due Capstone Discussion Proposals Due Oct 15 No class on.
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
1 COS 260 DAY 15 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz Today –Chapter 6 Assignment 4 posted –Due Nov 9 Capstone progress reports are due –Brief.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
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.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
1 COS 260 DAY 21 Tony Gauvin. 2 Agenda Questions? 8 th Mini Quiz corrected –Good results 9 Th Mini Quiz Today –40 min covering Chap 9 Assignment 5 Due.
1 COS 260 DAY 22 Tony Gauvin. 2 Agenda Questions? 9 th Mini Quiz corrected –Good results Assignment 5 Not corrected yet Assignment 6 Posted (one more)
1 COS 260 DAY 18 Tony Gauvin. 2 Agenda Questions? 7 th Mini quiz Graded –Good results 8 th Mini Quiz –Chap 8  Next class Assignment 4 Due Assignment.
Grouping objects Iterators, collections and the while loop Equality and Equality == and equals(…)
Fixed-sized collections Introduction to arrays 6.0.
Functional Processing of Collections (Advanced) 6.0.
Objects First with Java CITS1001 week 4
COS 260 DAY 1 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java CITS1001
Objects First with Java Introduction to collections
Fixed-sized collections
Loop Structures.
Functional Processing of Collections (Advanced)
COS 260 DAY 17 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
COS 260 DAY 19 Tony Gauvin.
COS 260 DAY 9 Tony Gauvin.
COS 260 DAY 6 Tony Gauvin.
COS 260 DAY 19 Tony Gauvin.
COS 260 DAY 27 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 10 Tony Gauvin.
COS 260 DAY 2 Tony Gauvin.
COS 260 DAY 18 Tony Gauvin.
COS 260 DAY 8 Tony Gauvin.
COS 260 DAY 3 Tony Gauvin.
COS 260 DAY 8 Tony Gauvin.
COS 260 DAY 15 Tony Gauvin.
Exercise 1 Declare a constant of type int called SIZE and initialize it to value 10 Declare two int arrays of size “SIZE” Assume that those int arrays.
COS 260 DAY 16 Tony Gauvin.
COS 260 DAY 19 Tony Gauvin.
COS 260 DAY 11 Tony Gauvin.
Collections and iterators
COS 260 DAY 23 Tony Gauvin.
COS 260 DAY 14 Tony Gauvin.
COS 260 DAY 4 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
COS 260 DAY 6 Tony Gauvin.
Further abstraction techniques
COS 312 DAY 18 Tony Gauvin.
Collections and iterators
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
Presentation transcript:

COS 260 DAY 13 Tony Gauvin

Agenda Mini-quiz Five Graded Fixed Size Collections Ok results Questions Assignment 3 posted Due Oct 20 Assignment 4 posted Due 0ct 31 Mini-quiz Five Graded Ok results Fixed Size Collections

Capstone Project Capstone Project Description Fall 2017.pdf October 2 Proposal Due E-mailed to Tony in Blackboard October 27 Progress Report E-mailed to Tony in Blackboard November 16 Progress Report E-mailed to Tony in Blackboard November 30 Progress Report E-mailed to Tony in Blackboard December 12@8AM All Deliverables & Presentation Due Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Fixed-sized collections Objects First with Java Fixed-sized collections Introduction to arrays 6.0 © David J. Barnes and Michael Kölling

for loop with bigger step Objects First with Java for loop with bigger step // Print multiples of 3 that are below 40. for(int num = 3; num < 40; num = num + 3) { System.out.println(num); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

for loop and Iterator No post-body action required. for(Iterator<Track> it = tracks.iterator(); it.hasNext(); ) { Track track = it.next(); if(track.getArtist().equals(artist)) { it.remove(); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Objects First with Java Review Arrays are appropriate where a fixed-size collection is required. Arrays use a special syntax. For loops are used when an index variable is required. For loops offer an alternative to while loops when the number of repetitions is known. Used with a regular step size. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved. © David J. Barnes and Michael Kölling

The automaton project An array of ‘cells’. Each cell maintains a simple state. Usually a small numerical value. E.g., on/off or alive/dead. The states change according to simple rules. Changes affected by neighboring states. https://cs.stanford.edu/people/eroberts/courses/soco/projects/2004-05/automata-theory/basics.html © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Cell states – blank cells are in state 0 A simple automaton nextState[i] = (state[i-1] + state[i] + state[i+1]) % 2; Odd-even Step Cell states – blank cells are in state 0 + 1 2 3 4 5 6 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Automation-V1 Exercise 7.24, 7.25, 7.26, 7.27 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

The conditional operator Choose between two values: condition ? value1 : value1 for(int cellValue : state) { System.out.print(cellValue == 1 ? ‘*' : ' '); } System.out.println(); Ex 7.28 , 7.29, 7.30 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Further advanced material

Arrays of more than one dimension Array syntax supports multiple dimensions. E.g., 2D array to represent a game board, or a grid of cells. Can be thought of as an array of arrays. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

The brain project Cell[][] cells; ... cells = new Cell[numRows][numCols]; for(int row = 0; row < numRows; row++) { for(int col = 0; col < numCols; col++) { cells[row][col] = new Cell(); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Alternative iteration for(int row = 0; row < cells.length; row++) { Cell[] nextRow = cells[row]; for(int col = 0; col < nextRow.length; col++) { nextRow[col] = new Cell(); } ‘Array of array’ style. Requires no access to numRows and numCols. Works with irregular shape arrays, which are supported in Java. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

Brain Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Update Rules for Brain Rules to update a cell A cell that is alive changes its state to dying A cell that is dying changes its state to dead A cell that is dead changes to alive if exactly two of its neighbors are alive, otherwise it remains dead Alive = 0, Dead = 1, Dying = 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

The Game of Life- Ex 7.68 https://bitstorm.org/gameoflife/ New rules Count neighbors that are alive If dead and 3 neighbors are alive, then change to alive If alive and < 2 or > 3 neighbors are alive, then dead Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Arrays and Streams java.util.Arrays has several stream() methods that return a Stream based on an array. IntStream is a Stream of int values. Instream.range() creates a sequential IntStream. toArray returns an array from a Stream. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.