Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Similar documents
Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers Sjaak Smetsers

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers

Assignment 3: Optimizing solutions

Assignment 6: Dodo keeps getting smarter

Assignment 4: Dodo gets smarter

Assignment 1: Meet Dodo

Assignment 8: Sokoban

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers

Assignment 7: Dodo s Race

Assignment 1: Meet Dodo

CS61B Lecture #2. Public Service Announcements:

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

Programming Techniques Workshop for Mindstorms EV3. Opening doors to the worlds of science and technology for Oregon s youth

2.5 Methods. You may have heard this song from when you were a child:

Functions. Learning Outcomes 10/1/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

Assignment 2.4: Loops

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

AP Computer Science Homework Set 1 Fundamentals

Lesson 6 page 1. If you look at the bottom right of the Scratch color choices, you will see it say MORE BLOCKS in Purple.

DCS/100: Procedural Programming

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Chapter 4 Introduction to Control Statements

HTML/CSS Lesson Plans

Repetition everywhere comparing while in a method and as an event. Comparison

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

EL2310 Scientific Programming

The for Loop. Lesson 11

Summer Assignment for AP Computer Science. Room 302

ORF 201 Computer Methods in Problem Solving. Lab 8: The Guassian Eliminator

CS111: PROGRAMMING LANGUAGE II

CS1 Lecture 3 Jan. 18, 2019

Claremont McKenna College Computer Science

CT 229 Arrays in Java

Pull Lecture Materials and Open PollEv. Poll Everywhere: pollev.com/comp110. Lecture 12. else-if and while loops. Once in a while

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

EASY

7. Arrays, More Java Looping

Programming in C++ PART 2

CS1 Lecture 3 Jan. 22, 2018

CS 4349 Lecture September 13th, 2017

ALICE: An introduction to progamming

Loops (while and for)

APCS Semester #1 Final Exam Practice Problems

Loops. Upsorn Praphamontripong. CS 1110/CS 1111 Introduction to Programming Spring 2018

Arrays and Other Data Types

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

QUIZ: What value is stored in a after this

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

1007 Imperative Programming Part II

Adapted from Code.org curriculum

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Programming Basics. Digital Urban Visualization. People as Flows. ia

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

Name: Magpie Chatbot Lab: Student Guide. Introduction

Mobile App:IT. Methods & Classes

Chapter 7. Iteration. 7.1 Multiple assignment

The first program: Little Crab

Introduction to the Java Basics: Control Flow Statements

Introduction to Software Development (ISD) Week 3

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CS113: Lecture 4. Topics: Functions. Function Activation Records

CSE 113 A. Announcements - Lab

nostarch.com/pfk For bulk orders, please contact us at

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Homework Set 1- Fundamentals

Stratford School Academy Schemes of Work

Creating Java Programs with Greenfoot

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Unit 1 Lesson 4. Introduction to Control Statements

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

AP Computer Science A

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

AP CS Unit 3: Control Structures Notes

CMSC201 Computer Science I for Majors

CS1020: DATA STRUCTURES AND ALGORITHMS I

GCSE Computer Science Component 02

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

What you can do: Use Transparency #10

Variables One More (but not the last) Time with feeling

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

Lecture Transcript While and Do While Statements in C++

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

These are notes for the third lecture; if statements and loops.

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Top-Down Program Development

1.00 Lecture 5. Floating Point Anomalies

Activity 6: Loops. Content Learning Objectives. Process Skill Goals

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

LOOPS. Repetition using the while statement

Introduction to C Final Review Chapters 1-6 & 13

Course Outline. Introduction to java

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Transcription:

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Today s Lesson plan (4) 20 min Quiz 10 min Looking back What did we learn last week? Discuss problems / homework (and handing-in) Blocks of theory and exercises / unplugged 10 min Wrapping up Next class: Fri Jan 8 th (NOT next week)

Swap Puzzle level 3 Describe a strategy In Java: square1 = square2; Which means: square 1 getspiecefrom square2

Swap Puzzle level 3

Computational thinking Working in a structured manner: Breaking problems down into subproblems Design, solve and test solutions to subproblems Combing these (sub)solutions to solve problem Analyzing the quality of a solution Reflecting about the solution chosen and proces Generalizing and re-use of existing solutions

Discuss problems / homework Only hand in (via email): MyDodo.java Document with answers to only (IN) questions Any problems? Please email!

Sequence flowchart code public methodname( ) { step1(); step2(); step3(); }

Selection (choice, if..then..else) public methodname( ) { flowchart code } if( check () ) { step1a(); }else{ step1b(); }

Repetition (iteration, loop) flowchart code public methodname( ) { while ( check () ) { dosomething (); } }

Challenge & problem You must perform two aspects well: 1) Create a problem-solving algorithm (a disciplined and creative process) We use a systematic approach 2) Formulate that algorithm in terms of a programming language (a disciplined and very precise process) Always check that your algorithm is correct by running/testing the implementation!

Today: Greenfoot Run: Act in a while loop Greenfoot.stop() Parameters Submethods: a method call in a method Boolean expressions (NOT, OR, AND)

Greenfoot Run Run is a special Greenfoot feature Run: Act called repeatedly Act in a while loop

>Run: built in iteration Can only be interrupted by: - Pressing Pause - Calling Greenfoot.stop()

>Run: calling act repeatedly What if your void act() contains a while-loop? Example: hatching a row of eggs

Iteration in act ACT Start Initial situation False NOT Border Ahead move True foundegg True False hatchegg End Final situation

Act in Run RUN False ACT Start NOT Stop NOT Border Ahead move True True One loop is superfluous Try to eliminate the act loop: Keep your act as simple/small as possible. foundegg True False hatchegg End

No iteration in act ACT Start False Greenfoot.stop NOT Border Ahead True move foundegg False hatchegg End

The golden-promise: Don t put too much work in the act method. Avoid time-consuming while-loops or while-loops with visible effects.

JAVA: Printing to screen(console) Printing text to the screen (console) with: System.out.println ( Hello ); Print a variable studentname to the screen with: System.out.println ( studentname); Print a combination of text and variable: System.out.println ( Hello + studentname); Example code: studentname = Jack ; System.out.println ( Hello + studentname); Outputs to screen: Hello Jack

Unplugged Songwriting Parameters Submethods

Songwriting: Parameters & Submethods Old MACDONALD had a farm E-I-E-I-O And on his farm he had a cow E-I-E-I-O With a moo moo here And a moo moo there Here a moo, there a moo Everywhere a moo moo Old MacDonald had a farm E-I-E-I-O. Song goes on for (just about) ever

More generic: Finding parameters Old MACDONALD had a farm E-I-E-I-O And on his farm he had a cow E-I-E-I-O With a moo moo here And a moo moo there Here a moo, there a moo Everywhere a moo moo Old MacDonald had a farm E-I-E-I-O Old MACDONALD had a farm E-I-E-I-O And on his farm he had a <ANIMAL> E-I-E-I-O With a <SOUND> <SOUND> here And a <SOUND> <SOUND> there Here a <SOUND>, there a <SOUND> Everywhere a <SOUND> <SOUND> Old MacDonald had a farm E-I-E-I-O

More generic: Using parameters Old MACDONALD had a farm E-I-E-I-O And on his farm he had a <ANIMAL> E-I-E-I-O With a <SOUND> <SOUND> here And a <SOUND> <SOUND> there.. Old MacDonald had a farm E-I-E-I-O System.out.println( Old MACDONALD had a farm ); System.out.println( E-I-E-I-O ); System.out.println ( And on his farm he had a + animal ); System.out.println( E-I-E-I-O ); System.out.println( With a + sound + + sound+ here ); System.out.println( And a + sound + + sound + there ) System.out.println( Old MACDONALD had a farm ); System.out.println( E-I-E-I-O );

Introducing parameters

Generic: Using parameters

More generic: finding repetition Old MACDONALD had a farm E-I-E-I-O And on his farm he had a cow E-I-E-I-O With a moo moo here And a moo moo there Here a moo, there a moo Everywhere a moo moo Old MacDonald had a farm E-I-E-I-O

Defining submethods [1] public void printoldmchadfarm ( ) { } System.out.println( Old MACDONALD had a farm ); public void singoldmcdonaldchorus ( String animal, String sound ) { } printoldmchadfarm ( ); System.out.println( "E-I-E-I-O" ); System.out.println( "And on his farm he had a " + animal ); System.out.println( "E-I-E-I-O" );

Why submethods [1]: easy to change Change in 1 place From: public void printoldmchadfarm ( ) { System.out.println( Old MACDONALD had a farm ); } Into: public void printoldmchadfarm ( ) { System.out.println( Old McDonald had a farm ); }

Defining submethod with arguments public void printhadanimal ( String animal ) { } System.out.println( And on his farm he had a + animal ); public void singoldmcdonaldchoruss ( String animal, String sound ) { } printoldmchadfarm(); printeieio(); printhadanimal ( animal ); printeieio (); printoldmchadfarm(); printeieio ();

Why submethods [2]: easy to read public void singoldmcdonald ( String animal, String sound ) { } printoldmchadfarm(); printeieio(); printhadanimal ( animal ); printeieio (); printwithsound (sound ); printandsound (sound ); printoldmchadfarm(); printeieio ();

Why submethods and arguments More generic: Less code Less mistakes Easier to read / understand Code can be used for more ( animals) Easier to change Easier to reuse

Your turn! The wheels on the bus go round and round, round and round, round and round. The wheels on the bus go round and round, all through the town. The doors on the bus go open and shut. The wipers on the bus go Swish, swish, swish On paper: Find parameters and replace text Find and use submethods Write method to print song using parameters & submethods

Boolean quiz Answer questions on paper (incl your name) Hand-in Papers will be shuffled Teacher chooses paper and reads last statement If this is you. DON T SAY A THING Everyone stands Teachers reads statements: If True about you: stay standing If False about you: sit down

Answer the following 1. What is your favorite number? 2. What is the color of your bicycle? 3. What is your favorite color? 4. What month were you born? 5. Do you have siblings? 6. What is the last digit of your phone number? 7. What is something about you that people here don t know and can t tell by looking at you?

Boolean Quiz

Boolean statements What it s about: In English, an or is often an exclusive or such as You can have chicken or fish. In English, you only get to pick one But with Boolean logic you could have chicken, fish, or both!! A B means: (A or B) or (A and B)

True or False? Booleans can be true or false Boolean statements can be made very complex using combinations: NOT:! AND: && OR: For example: (A B) &&! ( (A && B) C ) Careful: Often a source of errors!

Modifying code After each MINOR adjustment Compile Test if it still works If you do too much at once, and then get an error you re doomed to get frustrated! Remember, from our first lesson: Expect to make mistakes! Learn from them.

Computational thinking Working in a structured manner: Breaking problems down into subproblems Design, solve and test solutions to subproblems Combing these (sub)solutions to solve problem Analyzing the quality of a solution Reflecting about the solution chosen and proces Generalizing and re-use of existing solutions

Questions?

Wrapping up Homework for Wednesday 8:30 Jan.6 th 2016: Assignment 3: finish Assignment 4 up to and incl 5.2.2 Hand in: Via email : MyDodo.java and IN to Renske.weeda@gmail.com (Flowcharts: op paper in pigeonhole or photo/scan and paste into document)