February 16 - 20, 2009.  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:

Slides:



Advertisements
Similar presentations
RAPTOR Syntax and Semantics By Lt Col Schorsch
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
Introduction to Computers and Programming Lecture 9: For Loops New York University.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Loops – While, Do, For Repetition Statements Introduction to Arrays
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Looping Yong Choi School of Business CSU, Bakersfield.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops III Lecture 19, Wed Mar
CSE 113 Week 5 February , Announcements  Module 2 due 2/15  Exam 3 is on 2/15  Module 3 due 2/22  Exam 4 is on 2/25  Module 4 due 2/29.
Week 11 Recap CSE 115 Spring Want to write a programming language? You’ll need three things: You’ll need three things: –Sequencing –Selection Polymorphism.
The If/Else Statement, Boolean Flags, and Menus Page 180
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Copyright © Texas Education Agency, Computer Programming For Loops.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
Repetition Statements while and do while loops
3. Controlling Program Flow Methods, parameters, and return values Boolean expressions Conditional branching Loops.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Often being different. Control flow By default Java (and therefore Processing) executes lines of a program one after the other –Doesn’t matter what happened.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Repetition 8/9/2009. Learning to Program -- Suggestions Spend a lot of time fiddling around with code –Programming is something you have to learn by doing.
Chapter 9 Control Structures.
CISC105 – General Computer Science Class 4 – 06/14/2006.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Loops. More Flow of Control  Sometimes we want to do something many times.  Don’t have to write all the steps out multiple times.  Use a LOOP – control.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
LOOPS IN ‘C’ PROGRAMMING. V ERY O FTEN, Y OU W ILL W ANT TO D O S OMETHING M ORE T HAN O NCE HA.
Loops. About the Midterm Exam.. Exam on March 12 Monday (tentatively) Review on March 5.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Chapter 9 Repetition.
Chapter 4 Repetition Statements (loops)
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Topic 6 Modifying Pictures Using Loops
Loop Structures.
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Computation as an Expressive Medium
CS 106A, Lecture 7 Parameters and Return
Chapter 5 Repetition.
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Outline Altering flow of control Boolean expressions
LRobot Game.
Chapter 9 Control Structures.
Lab5 PROGRAMMING 1 Loop chapter4.
Manipulating Pictures, Arrays, and Loops
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
February , 2009 CSE 113 B.
Seating “chart” Front - Screen rows Back DOOR.
Manipulating Pictures, Arrays, and Loops
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
CSC1401 Manipulating Pictures 2
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Loops CGS3416 Spring 2019 Lecture 7.
Presentation transcript:

February , 2009

 2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2: Exam 2  3/4: Go over Exam 2  3/6: Exam 2 Makeup

 Method that takes in a pixel location and returns the color of that pixel. public java.awt.Color getColorAtPixel(int x, int y) { //Get the pixel at the location (x,y) Pixel pixel = _pic.getPixel(x,y); //Get the color from that pixel java.awt.Color color = pixel.getColor(); //return the color to the caller of the method return color; }

 Comments are text inserted into the program for humans to read.  Comments are ignored by the compiler.  Comments can be of two types:  // starts a to-the-end-of-line comment  /* is the start of a multi-line comment  Which ends with */  DrJava colors comments green to differentiate them from the rest of the code.

 Write a method that takes in a pixel location and a color and sets the color of that pixel to the color passed in as the parameter. public void getColorAtPixel(int x, int y, java.awt.Color color) { //Get the pixel at the location (x,y) Pixel pixel = _pic.getPixel(x,y); //Set the color of that pixel pixel.setColor(color); }

 If we want the computer to do something over and over for us, we need to use repetition.  Different programming languages implement repetition in different ways.  Most languages have loops as a way to implement repetition.  Java has several different types of loops, one of them is the for-loop.

for(initialization; boolean expression; increment) { //loop body } The parts in black above are necessary syntax. The other parts are the names of the sections of the loop syntax. Let’s take a closer look at how a loop is executed in the machine and the different sections of the loop.

Code executed before the for keyword Initialization Boolean Expression truefalse This the code that has been executed before we want to loop Then we initialize the loop counter – create a variable to help us keep track of how many times we’ve looped A boolean expression is one that evaluates to true or false. Depending on the evaluation, we will do two different things. This expression controls whether we keep looping or stop looping.

loop body Increment Boolean Expression truefalse This is the code in the program after the loop is finished. Increment our loop counter (usually by 1) to tell us that we have executed the loop one more time. This is the part of the code that is executed over and over again. Execute the rest of the code in program Go back to the boolean expression to see if we need to execute the loop again

for (int count = 1; count <= 5; count++) { System.out.println(“Hello”); }  We typed this in at the interactions pane and saw the five “Hello”s on the screen.  Remember that count++ is a shortcut way of writing count = count + 1

public void printHello5Times() { for(int count = 1; count <= 5; count++) { System.out.println("Hello"); }  Now we can call this method and see the Hellos on the screen.

public void printHelloNTimes(int numberOfTimes) { for(int count = 1; count <= numberOfTimes; count++){ System.out.println("Hello"); } Notice the parameter that will tell us how many times Hello should be printed. When we call this method, we need to pass in the actual number of times to print Hello.

public void printHelloPictureWidthTimes() { for(int count=1; count<=_pic.getWidth(); count++){ System.out.println("Hello"); }

public void printPictureWidth() { for(int count=1; count<=_pic.getWidth(); count++){ System.out.println(count); } System.out.println(“The width of the picture is ” + _pic.getWidth()); } The + in the last print statement is the string concatenation operator. It allows us to combine strings together (or in this case, a string and a number).

 We can write similar methods for looping through the height of a picture.  If we want to loop through all the pixels, then we need to combine the looping of the width and the height of a picture.  Putting two loops together is called nesting of loops.

Note that this is slightly different than what was talked about in lecture on Friday for(int column=0; column<_pic.getWidth(); column++){ for(int row=0; row<_pic.getHeight(); row++){ }

public void printOutColorsOfPixels() { for(int column=0;column<_pic.getWidth();column++){ for(int row=0; row<_pic.getHeight(); row++) { Pixel pixel = _pic.getPixel(column, row); System.out.println(pixel.getColor()); } System.out.println("This picture is: " + _pic.getWidth()+" pixels wide "+" and " + _pic.getHeight()+" pixels tall."); }

 We can use the basic format of the previous method any time we need to do something with the pixels of a picture.  The only line that would need to change is the line after we get the pixel object. We use that line to do whatever we want to change the pixel.

public void sampleLoopForPictures() { for(int x = 0; x < _pic.getWidth(); x++){ for(int y = 0; y < _pic.getHeight(); y++) { Pixel pixel = _pic.getPixel(x, y); // Insert code for what you want to do // with pixels here. }