10-15 Class Notes CS 107

10-15 Class Notes CS 107 - theColor = "red"; }...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Announcements: We are ending week 8, more than half way through the semester! Questions? Last Time: Arrays: declaration, syntax, passing as parameters, usage in counting input characters Today: Square[] dice; 1. Declare the array as an instance variable 2. Allocate space for the array // allocate memory for the array of squares dice = new Square[ 10]; 3. Allocate memory for each of the dice within the array of squares Key ideas: Example of making an array of Squares (maybe someday you will need this…) // allocate memory for square within the dice array for( int i=0; i<dice.length; i++) { // set alternating colors String theColor = "blue"; if( i%2 == 1) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: theColor = "red"; } dice[ i] = new Square( (10+5)*i, 120, 10, theColor, true, "0"); } First, intuition on how to do this More examples of using arrays: sorting using Bubble Sort 10-15 Class Notes CS 107 Friday, October 15, 2010 3:52 PM 107 Fall 2010 Page 1 Think about how you might want to do a selection sort , where you find the largest (or smallest) value on each pass through the data, swapping it into place. How does this compare to Bubble sort? See other approaches to sorting given online on the course web site: http://people.cs.ubc.ca/~harrison/Java/sorting-demo.html 107 Fall 2010 Page 2...
View Full Document

This note was uploaded on 02/10/2012 for the course COP 2271 taught by Professor Reed during the Fall '10 term at University of Central Florida.

Page1 / 2

10-15 Class Notes CS 107 - theColor = "red"; }...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online