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

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

Assignment 4: Dodo gets smarter

Assignment 3: Optimizing solutions

Assignment 1: Meet Dodo

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

Assignment 8: Sokoban

Assignment 6: Dodo keeps getting smarter

Assignment 1: Meet Dodo

Assignment 7: Dodo s Race

Lesson 2.4 Arraylist

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Java Review. Fundamentals of Computer Science

Getting to know Greenfoot

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Pointers, Arrays and Parameters

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

APCS Semester #1 Final Exam Practice Problems

Open and respond to this poll: PollEv.com/comp110. Calling Methods Mr. Roboto

Ticket Machine Project(s)

Computer Programming

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

Another interface: Comparable

Lesson 12: OOP #2, Accessor Methods (W03D4)

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

AP Computer Science Homework Set 1 Fundamentals

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Express Yourself. Writing Your Own Classes

Announcements. 1. Forms to return today after class:

If you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider:

Welcome to... CS113: Introduction to C

Chapter 4 Defining Classes I

Inheritance and Interfaces

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

Curriculum Map Grade(s): Subject: AP Computer Science

Lecture Transcript While and Do While Statements in C++

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

CS1004: Intro to CS in Java, Spring 2005

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

HTML/CSS Lesson Plans

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

Recap: Pointers. int* int& *p &i &*&* ** * * * * IFMP 18, M. Schwerhoff

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Activity Logging Lecture 16

AP Computer Science Summer Work Mrs. Kaelin

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

Claremont McKenna College Computer Science

Designing Robust Classes

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

CITS1001 week 4 Grouping objects

Last time s big ideas

CITS1001 week 4 Grouping objects lecture 2

Lecture 2: Variables & Assignments

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Recommended Group Brainstorm (NO computers during this time)

Computer Science 210: Data Structures

University of Hull Department of Computer Science. Wrestling with Python Week 04 Using Lists

Answer Key Lesson 5: Area Problems

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Computer Programming

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

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

AP Computer Science Principles Programming Question Tips. 1: Which algorithm/code segment achieves some result?

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

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

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

CMSC 201 Spring 2019 Lab 06 Lists

CS 302 Week 9. Jim Williams

4. Java language basics: Function. Minhaeng Lee

Inf1-OOP. OOP Exam Review. Perdita Stevens, adapting earlier version by Ewan Klein. March 16, School of Informatics

CMSC 341 Lecture 7 Lists

Unit 4: Client View of a Component Methods

Creating Java Programs with Greenfoot

Data Types primitive, arrays, objects Java overview Primitive data types in Java

CMSC 201 Computer Science I for Majors

Methods. Methods. Mysteries Revealed

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

Carrera: Analista de Sistemas/Licenciatura en Sistemas. Asignatura: Programación Orientada a Objetos

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

WELCOME! (download slides and.py files and follow along!) LECTURE 1

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

Design and Debug: Essen.al Concepts CS 16: Solving Problems with Computers I Lecture #8

The high-level language has a series of primitive (builtin) types that we use to signify what s in the memory

CS 170 Java Programming 1. Week 10: Loops and Arrays

October 6, SET-UP (Activate Prior Knowledge & Connect to Challenge Question)

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

CS1 Lecture 3 Jan. 18, 2019

CS 1110: Introduction to Computing Using Python Loop Invariants

Transcription:

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

Today s Lesson plan (3) 10 min Looking back What did we learn last week? Discuss problems / homework (and handing-in) Answers PRE-task Sneak preview Blocks of theory/unplugged and exercises 10 min Wrapping up Homework Next week: quiz

Discuss problems / homework Problems handing-in? We re missing: Assignment 1: Martijn & Jelmer (ex 5.5 until the end) Lieke & Mats Tim Assignment 2: Martijn & Jelmer Bram & Tim Please still hand-in!

Discuss problems / homework Problems handing-in? Where to find assignments and hand-in homework? Assignments posted on magister Class appointment Homework due Wednesday on today s date or next week?? Hand-in: email to Renske.weeda@gmail.com Paper: pigeon hole Renske Smetsers PAX students: paper during Thursday s INF class

Discuss problems / homework Give instructions from object s (mydodo s) perspective i.e. moveforward (instead of moveright )

Discuss problems / homework Method call vs. Method declaration Demo of steps to writting new code: Adding a method to turn mydodo to the left Tip: Dodo has a turnright method

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!

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 Getter vs. setter methods A class has it s own: Methods Data No other object may touch/change this (safe idea!!!) Want info: ask the object with a get method Want to change data: ask the object with a set method Object changes/gives data (if you are allowed)

Getter vs. Setter methods getnrofeggs: Question Dodo, tell me how many eggs you have laid setnrofeggs; Statement Dodo: this is the number of eggs you have to do something with

Types Say which types you want to use only: When you declare something Eg: a method declaration int getnrofeggsneeded ( ) {. // this is how eggs Mimi must retrieve } Afterwards, when you use a method: DON T declare, just USE it! Also in flowcharts! using a method in code: while (nreggsfound < getnrofeggsneeded ( ) ) { findmoreeggs(); }

Pre-task (discuss answers)

Sneak preview

What did we learn last week? Parameters, signatures, method calls, results Mutator / accessor methods Flowcharts

Accessor methods (questions) flowchart code CAN MOVE True Start NOT border Ahead Initial situation: Dodo is standing in the world False public boolean canmove() { if (! borderahead () ) { return true; } else { return true return false } return false; } End Final situation: equal to initial situation 17

Mutator methods (behavior) flowchart code SEARCH FOR FOOD Start Initial situation: searching for food public void act() { move move(); eatfood True foundfood? False if ( foundfood() ) { eatfood(); gohome(); } gohome } Einde Final situation: Still searching for food or heading home 18

Anatomy of a method (1) Signature: first line of a method declaration (up to { ) public void jump( int distance ) { }

Anatomy of a method (3) What answer (value) is returned? void = nothing returned int = returns an integer (0, 1, 2,...) etc. a method can return anything public void jump( int distance ) { }

Anatomy of a method (3) Name of this method public void jump( int distance ) { }

Anatomy of a method (4) Parameters for passing info to this method (here one). Parameter type: the kind of information passed Parameter name public void jump( int distance ) { }

Anatomy of a method (5) Return a boolean (true or false) public boolean canjump( int distance ) { } << body >>

Today s Lesson Goals Checking and assigning values Algorithms & flowcharts: Sequences Selection (if-then-else) Repetition (While) Structured code modification & debugging Quality of a solution

Counting Starts at.

Unplugged: Swap puzzle What it s about: Coming up with an algorithm Looking/planning ahead Efficiency Testing

Swap Puzzle Pieces start on different (non-white) color A piece can move to an empty adjacent square Can jump over an adjacent piece of other color onto an empty square Method to use: getsthepiecefrom Step 1: Square 1 GETS THE PIECE FROM Square 0 Solve the puzzle in the least amount of steps Write down the steps

Swap Puzzle level 1

Swap Puzzle level 2 Challenge: Most efficient algorithm? - What to count/compare with? - How to test?

Swap Puzzle level 2

Assigning values SQUARE 1 GETS THE PIECE FROM SQUARE 2 Means: Set SQUARE 1 to (value of) SQUARE 2 In Java code: square1 = square2;

Swap Puzzle level 3 Which pair can find the algorithm with min. # steps? Less writing? Use: sq1 = sq2 Which means: square 1 getspiecefrom square2 When you re sure you know (and tested): Check that it can t be done faster (count #steps) Check your steps Hold op your hand Challenge: class will execute your steps

Swap Puzzle level 3

Swap puzzle: what its about Describing your steps => algorithm! Series of actions to get the job done Algorithm? Then you ll still have solution next week Importance of testing: before: step through your answer (like processor) after: don t assume it works, check it! Efficiency Think of a solution that works, then check efficiency Looking ahead vs. trail and error Consider all possible moves Necessary when the puzzle gets harder

Swap-puzzle and assigning values Assigning values using = SQUARE 1 GETS THE PIECE FROM SQUARE 2 Means: Set SQUARE 1 to (value of) SQUARE 2 In Java code: square1 = square2; Check value using == In Java, to check if square1 is red: if ( square1 == red ) { }

Checking values! Means NOT && Means AND Means OR

Java building blocks (for specifying behaviour) Control structures: constructions to compose programs, Who are you? I m Mimi Sequence Selection (Choice) Repetition 37

Specifying behavior Control structures: constructions to compose programs, like: Sequence: Selection: Repetition: stepa; stepb; if ( check() ) then stepsthen else stepselse while ( check() ) stepswhile

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

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

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

Turn to North Algorithm Flowchart Code Given the method: boolean facingnorth( )

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!

Steps in making a solution 1. Think -> Algorithm 2. Flowchart 3. Code public.. methodname( ) { step1(); step2(); step3();

Debugging (fixing mistakes) 1. Remove compile errors 2. Check if code represents flowchart 3. Check if flowchart represents algorithm 4. Check for thinking-errors in your algorithm public.. methodname( ) { step1(); step2(); step3();

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!

Questions?

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

Wrapping up Homework for Wednesday 8:30 December 9 th : Assignment 2: 2: All All ex. ex. incl incl diagnostic test test 6.1 6.1 and and 6.2 6.2 Renske.weeda@gmail.com Assignment 3: up to and including 5.1 Assignment 3: up to and including 5.1 ZIP code and IN and email to Flowcharts: on paper in pigeonhole or photo/scan and paste into document All course downloads on: http://www.cs.ru.nl/~sjakie/greenfoot/kandinsky/ Next week: Quiz

Wrapping up Quiz: what to expect? Assignment 1 & 2 Difference between accessor/mutator methods Signature of a method (incl parameters, results) Types (such as int, boolean, String, void) Inheritance (class diagram) Explain flowcharts: sequence, selection, repetition Transform an algorithm into flowchart Reflection/evaluation: tips/tops