10-15 Class Notes CS 107

# 10-15 Class Notes CS 107 - theColor ="red" dice i...

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

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) {

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

View Full Document
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern