Teaching Control Structures, using objectdraw Chris Nevison Barbara Wells.

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Java Control Statements
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
Control Flow Statements: Repetition/Looping
Chapter 2 - The First Program: Little Crab
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
1 Repetition structures Overview while statement for statement do while statement.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Programs Involving Repetition Drawing Grass Drawing grids Printing marks on a ruler Repeatedly rolling dice in craps game.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Programming What is a program? –A set of instructions –Understood by a computer.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Java Loops (Java: An Eventful Approach, Ch 7 and 13), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture 16 6 November 2012.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Repetition Statements while and do while loops
03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
February ,  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:
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Graphics Tools and Parameters Chris Nevison Barbara Wells.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Alice in Action with Java Chapter 4 Flow Control.
Lesson thirteen Conditional Statement "if- else" ©
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
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.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Follow up from lab See Magic8Ball.java Issues that you ran into.
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 3: Decisions and Loops
Loops in Java.
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.
While Loops Chapter 3.
Iteration with While You can say that again.
LRobot Game.
Lecture Notes – Week 3 Lecture-2
Chapter (3) - Looping Questions.
Unit 3 - The while Loop - Extending the Vic class - Examples
Programs Involving Repetition
More programming with "Processing"
Chapter 8: More on the Repetition Structure
Lec 4: while loop and do-while loop
Control structures Chapter 3.
Control structures Chapter 3.
CS2011 Introduction to Programming I Selections (I)
Control structures Chapter 3.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

Teaching Control Structures, using objectdraw Chris Nevison Barbara Wells

Problem: Controlling the Elevator Buttons for UP and DOWN Elevator moves in direction according to Button "pushed" (clicked with mouse)

Java Constructs boolean values, expression –true or false –some methods return booleans –expressions include comparison of numbers if statement –takes boolean expression –true, execute body –false, execute else part, if any Syntax exactly like C++

objectdraw constructs Geometric objects –FilledRect, FilledOval,Text Methods for geometric objects –move, moveTo void, change position parameters determine movement –contains returns boolean –true if Location parameter is inside oval –false otherwise

public class ElevatorSystem2 extends WindowController{ private FilledRect elevator; private FilledOval upButton; private FilledOval downButton; private Text upText; private Text downText; public void begin() { elevator = new FilledRect(100, 200, 20, 30, canvas); upButton = new FilledOval(160, 30, 20, 20, canvas); downButton = new FilledOval(160, 60, 20, 20, canvas); elevator.setColor(Color.blue); upButton.setColor(Color.yellow); downButton.setColor(Color.yellow); upText = new Text("UP", 182, 33, canvas); downText = new Text("DOWN", 182, 63, canvas); }

public void onMouseClick(Location point) { if(upButton.contains(point)){ elevator.move(0.0, -60.0); } else if(downButton.contains(point)){ elevator.move(0.0, 60.0); } returns boolean moves elevator up moves elevator down

Teaching Points Teach if structure with interesting context Immediate visual feedback

Exercise: three levels 1. Indicate three floors by drawing three lines see API for Line class 2. Place one button at each floor 3. When button is pushed, elevator should move to that floor

Repetition loops repeat action as long as a certain condition is true –condition usually depends on a variable that changes within the loop basic loop is while while( > ){ > }

Example: drawing parallel lines public class ParallelLines1 extends WindowController{ public void begin() { Location startLine = new Location(0, 0); Location endLine = new Location(300, 0); int k = 0; while(k < 200){ startLine.translate(0, 10); endLine.translate(0, 10); new Line(startLine, endLine, canvas); k++; }

Exercise: Draw something using repetition Scene with grass or fence or other repetitive element polka dot pattern (Dalmation?) –look up java.util.Random