Assignment 8: Sokoban

Size: px
Start display at page:

Download "Assignment 8: Sokoban"

Transcription

1 Assignment 8: Sokoban Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license, 1 Introduction In this assignment you will write a game in Greenfoot known as Sokoban. See info/ for an example. Our variation is called Mimi the eggs-hoarder. The original game takes place in a warehouse. The player is a warehouse employee whose task is to push crates to the correct location. This game is played in the Madagaskar world; the world in which Mimi lives. The goal is for Mimi to push all the eggs into the nests. The following rules apply: Mimi can only push eggs forward, she can t pull an egg; Mimi cannot sit on an egg or step over it; Mimi can only push one egg at a time. As a consequence, Mimi cannot push two (consecutive or adjacent) eggs simultaneously; No two eggs can occupy one cell (not even in a nest); A nest can hold only one egg; An egg can be pushed out of a nest; Neither Mimi nor an egg can be pushed through a fence; Mimi can step over a nest (of course, very carefully so that she doesn t destroy it). If the nest holds an egg, she will push the egg out; There are as many nests in the world as eggs; The level is completed when each nest is filled with an egg.

2 2 Learning objectives After completing this assignment, you will be able to: handle user interaction in the code; apply nested if.. then.. else statements; apply the knowledge from previous assignments to implement a game on your own. 3 Instructions For this assignment you will need the DodoScenarioSokoban scenario. 4 Theory Contrary to the previous assignments, you will not implement an algorithm to make Mimi do something. This time the user directs Mimi by pressing a key, and in the code we must explain what Mimi must depending on which key is pressed. We start by explaining a particular use of if.. then.. else statements, this time in the context of Sokoban. This is needed to incorporate user-interaction for the different keys. Nested if.. then.. else.. statements You can test multiple cases simultaneously using a nested if.. then.. else statement. This was explained in assignment 7, using a general example. We will now give a Greenfoot example that will also be used in this assignment. Example: Suppose we want to check whether the user has pressed one of the arrow keys on the keyboard, and if so, have Mimi face that direction. Code using nested if.. then.. else.. statements The Greenfoot method boolean iskeydown (String key) tests whether the user has pressed a particular key. For example, to check whether the arrow-up button has pressed, the following method is called: Greenfoot. iskeydown ("up" ) ; Similarly, the string "left" is associated with left-arrow-key, "right" with the right-arrow-key, and "down" with the down-arrow key. In the handlekeypress method this test is used to determine which key has been pressed and changes the direction in which Mimi is facing accordingly: public void handlekeypress( ) { if ( Greenfoot. iskeydown( "left ") ) { setdirection ( WEST ) ; else { if ( Greenfoot. iskeydown( "right" ) ) { setdirection ( EAST ) ; else { if ( Greenfoot. iskeydown( "up" ) ) { setdirection ( NORTH ) ; Algorithmic thinking and structured programming (in Greenfoot) 2

3 else { if ( Greenfoot. iskeydown( "down" ) ) { setdirection ( SOUTH ) ; Flowchart using nested conditional statements: The corresponding flowchart looks like this: Figure 1: Flowchart for handlekeypress Note: As a result of the numerous accolades and the fact that the code stretches further and further to the right, the code becomes hard to oversee and furthermore being errorprone. Code using else.. if.. statements In Java, there is an alternative way for writing these types of nested conditional statements. Most programmers combine the else and the if into one code-line using an else.. if.. statement. The method handlekeypress then becomes: public void handlekeypress( ) { if ( Greenfoot. iskeydown( "left" ) ) { setdirection ( WEST ) ; else if ( Greenfoot. iskeydown( "right" ) ) { setdirection ( EAST ) ; else if ( Greenfoot. iskeydown( "up" ) ) { setdirection ( NORTH ) ; else if ( Greenfoot. iskeydown( "down" ) ) { setdirection ( DOWN ) ; Note: This results in less lines of code, and furthermore, the code-structure becomes much clearer. Algorithmic thinking and structured programming (in Greenfoot) 3

4 5 Exercises (implementation of the game) For this assignment you will start with a brand new scenario. Compared to the previous scenarios, some minor modifications have been made. The most important addition is the MovableActor class. Each Dodo can be moved (and is thus movable), and now belongs to the MovableActor class. Contrary to the previous assignments, Eggs can now be moved too. As a consequence, Eggs now belong to the MovableActor class too. The class diagram shows both Dodo and Egg as sub-classes of MovableActor. The MovableActor class basically has no new functionality. The main difference is that several move -related methods such as void step ( int direction) and boolean borderahead (int direction) have been moved from the Dodo class to the MovableActor class. Mimi now inherits these methods from MovableActor. See figure 2: Figure 2: Methods which Dodo inherits from MovableActor Because Eggs now also belong to the MovableActor class, they too can use the step and borderahead methods. In addition, several new methods have been added to the Egg class. The most important are: void push ( int direction): which allows an egg to be pushed in a particular direction. This direction is passed as a parameter. boolean canbepushed ( int direction ): which can be used to test if an egg can be moved in the specified direction. 5.1 Getting started 1. Download and open the DodoScenarioSokoban scenario; 2. Compile the scenario and press Run. Mimi should run along the inside of the fence that encloses the world. 3. Using the right-mouse-button, test the new Egg methods push and canbepushed several times, each time with the egg in a different position in the world. Do these methods work as expected? 4. Replace the code in MyDodo s act method by a call of the method handlekeypress. 5. Compile and run the scenario (by pressing the Run button). Desbribe what happens. If nothing happens, then press one of the arrow keys on your keyboard. As you can see the handlekeypress method is not complete yet. Which key(s) does Mimi respond to? Which doesn t Mimi respond to. 5.2 Mimi responds to arrow keys As you may see, lots of things don t work properly yet. Mimi walks through fences and over eggs, and does not adequately respond to the arrow keys pressed by the user. In this task you will create order in Mimi s world. We start by fixing Mimi s behavior to the user s instructions: Algorithmic thinking and structured programming (in Greenfoot) 4

5 1. Open the MyDodo class in the editor and find handlekeypress. 2. Have a look at the body of the handlekeypress method. Here, a submethod called getnewdirection is used. 3. Consider where you have to change which code so that Mimi adequately responds to all the arrow keys. Tip: Have a look at the theory block above about Nested if.. then.. else.. statements in which the Greenfoot method iskeydown is discussed. 4. Adjust and compile MyDodo. 5. Run the scenario and make sure Mimi indeed responds to each arrow key adequately. If not, adjust your code. 5.3 Mimi pushes eggs forward (A) Mimi takes a step when the user presses an arrow button. However, if Mimi is in front of an egg, she shouldn t merely take a step. More must happen! We will now ensure that Mimi doesn t just step over an egg, but that she pushes it forward. We will now adjust handlekeypress to work as expected. To do so, follow the next tips: First decide which specific cases should be distinguished and adjusted; The Dodo class contains all the methods which you need to distinguish these cases; Obviously, the new Egg methods will be useful; Mimi can check whether there is an egg laying directly in front of by calling eggahead; Mimi can get a hold of the egg using geteggahead; Using the existing methods, she can ask the egg whether or not it can be pushed, and if so, push it forwards and then (in the same direction), take a step herself. Compile and test your changes. Systematically try a few cases. Fix any errors you encounter. Make sure that Mimi indeed complies to all the rules described in chapter Scoreboard We need a scoreboard in order to track how many steps Mimi has taken and how many eggs she has already placed in a nest. We will let Mimi keep track of these scores herself and have a scoreboard display the values. Do this as follows: 1. First, add two instance variables to MyDodo for storing this information (one for number of steps taken, the other for the number of eggs in a nest). Consider meaningful names, appropriate types and a suitable initial value. 2. As soon as Mimi takes a step, change the value of the instance variable for the number of steps taken. 3. After each step, call updatescores to ensure that the changed situation is actually displayed on the scoreboard. 4. To ensure you haven t made any mistakes thus far, compile and test your changes before proceeding. 5. Now add the second variable to keep track of how many eggs have been placed in a nest. Consider when and how you can determine this. Tip: The Dodo method boolean nestahead() may be useful. Algorithmic thinking and structured programming (in Greenfoot) 5

6 6. Again, call updatescore. 7. Compile and test your program. 5.5 Egg in its nest At the time-being, when an egg is pushed into a nest, you can t see it anymore. This is because the egg and the nest are in the same cell, and the egg is hidden behind the nest. That s too bad! Let s change that. So, if an egg is pushed into a nest, we want to show a nest with an egg in it. To do this, we first adjust the Nest class. 1. Open the Nest class in the editor. 2. Add an instance variable to this class which indicates whether the nest is empty or not. Ensure that this variable gets an appropriate initial value (i.e. when a new nest is brought into the world, what should its value be?). 3. Add a method to fill the nest when appropriate. The effect of this is not only to change the value of the instance variable, but also to adjust the picture which is shown. Tip: Look back to assignment 6 To be hatched or not to be hatched in which you did something similar. There, in the class Egg, you also changed the picture of an egg into a hatched egg. 4. Compile and test your program using your right-mouse-button. 5. Similarly, add a method to empty the nest when an egg is pushed out. 6. Compile and test your program using your right-mouse-button. 7. Also adjust your MyDodo class. First consider what exactly must happen and where your code needs to be adjusted. Recall that the nest itself does not know whether or not it contains an egg; Mimi, however, does! To change the state of the nest, you need (a reference to) the nest object. Which method can you use to do this? Keep in mind that you can also push an egg out of a nest. 8. Compile and test your program, this time also run the scenario. 5.6 Level achieved (A) The program must now decide whether the level has been completed or not. We introduce a referee to make this decision. 1. Have a look at the code of the Referee class. 2. At the top of the class an instance variable myworld is declared which references to the world. Further down, you can find a method updatescoreboard. This method is used in the Dodo class and wille called as soon as updatescores adjusts the score. If you wish, you can check this yourself by opening the Dodo class in the editor and having a look at the updatescores method. 3. The second score, called score2 indicates how many eggs are already in a nest. If this is equal to the number of eggs in the world, the level has been completed. Add a method that checks whether the game is over. If this is true, call the method levelfinished. Tip: Use the World method getobjects to determine how many eggs the world contains. Have a look at the Java documentation about what the method does and consider how you can use the result of this method to determine if the level has been completed or not. Algorithmic thinking and structured programming (in Greenfoot) 6

7 5.7 Optional: Oops.. undo? Finally, it is still a bit unsatisfying that when the user accidentally presses the wrong key he may not be able to complete the level anymore (he gets into a situation in which the level cannot longer be solved). An undo function would be helpful. In order to achieve this, some code adjustments must be made in the mydodo class. We will only give some general indications on how to do this; its up to you to come up with and implement the details. 1. Determine a suitable key for an undo. Add a method to handle the user-interaction. 2. Determine which information must be remembered/stored in order to undo a move. 3. Besides having Mimi take a step back, sometimes an egg s position must be restored (or undone) too. 4. Consider what should happen if the user wants to undo multiple steps. 5. Does the correct value appear on the scoreboard after an undo? 5.8 Optional: New levels Add your own new challenging levels to the scenario. Let a fellow student test whether they are solvable or not. Also have them decide what the level s difficulty is. 6 Summary You can now: handle user-interaction (keyboard input); make use of else if statements; use what you have learned in previous assignments to write a game on your own. 7 Saving your work You have just finished the bonus assignment. Save your work! 8 Handing in Hand your (digital) work in via to renske.weeda@gmail.com: Algorithmic thinking and structured programming (in Greenfoot) 7

Assignment 6: Dodo keeps getting smarter

Assignment 6: Dodo keeps getting smarter Assignment 6: Dodo keeps getting smarter Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0

More information

Assignment 4: Dodo gets smarter

Assignment 4: Dodo gets smarter Assignment 4: Dodo gets smarter Algorithmic Thinking and Structured Programming (in Greenfoot) 2017 Renske Smetsers-Weeda & Sjaak Smetsers 1 Contents Introduction 1 Learning objectives 1 Instructions 1

More information

Assignment 3: Optimizing solutions

Assignment 3: Optimizing solutions Assignment 3: Optimizing solutions Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license,

More information

Assignment 1: Meet Dodo

Assignment 1: Meet Dodo Assignment 1: Meet Dodo Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license, https://creativecommons.org/licenses/by/4.0/

More information

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

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers Sjaak Smetsers Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers Sjaak Smetsers Today s Lesson plan (3) 10 min Looking back What did we learn last week? Blocks of: Theory Exercises

More information

Assignment 7: Dodo s Race

Assignment 7: Dodo s Race Assignment 7: Dodo s Race Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license, https://creativecommons.org/licenses/by/4.0/

More information

Assignment 1: Meet Dodo

Assignment 1: Meet Dodo Assignment 1: Meet Dodo Algorithmic Thinking and Structured Programming (in Greenfoot) 2017 Renske Smetsers-Weeda & Sjaak Smetsers 1 Contents Introduction 1 Learning objectives 2 Instructions 2 Theory

More information

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 Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Computational thinking Working in a structured manner: Breaking problems down into subproblems

More information

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 Ana Tanase Today s Lesson plan (3) 10 min Looking back What did we learn last week? Discuss

More information

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 Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Assignment 5: difficulties Write a method int degreesneededtoturntofacenorth( ) which returns

More information

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 Ana Tanase Today s Lesson plan (10) Retrospective Previous lesson Theory: Nested if.. then..

More information

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 Ana Tanase Today s Lesson plan (4) 20 min Quiz 10 min Looking back What did we learn last week?

More information

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 Ana Tanase Today s Lesson plan (7) Mid-Task Flowcharts (Real world example) Unplugged activity:

More information

The first program: Little Crab

The first program: Little Crab Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

Improving the Crab more sophisticated programming

Improving the Crab more sophisticated programming CHAPTER 3 Improving the Crab more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter,

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

Getting to know Greenfoot

Getting to know Greenfoot CHAPTER 1 Getting to know Greenfoot topics: concepts: the Greenfoot interface, interacting with objects, invoking methods, running a scenario object, class, method call, parameter, return value This book

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Creating Java Programs with Greenfoot

Creating Java Programs with Greenfoot Creating Java Programs with Greenfoot Working with Source Code and Documentation 1 Copyright 2012, Oracle and/or its affiliates. All rights Objectives This lesson covers the following topics: Demonstrate

More information

Improving the crab: more sophisticated programming

Improving the crab: more sophisticated programming Chapter 3 Improving the crab: more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter,

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

Java Review. Fundamentals of Computer Science

Java Review. Fundamentals of Computer Science Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions

More information

Computer Science 202 Introduction to Programming The College of Saint Rose Fall Topic Notes: Conditional Execution

Computer Science 202 Introduction to Programming The College of Saint Rose Fall Topic Notes: Conditional Execution Computer Science 202 Introduction to Programming The College of Saint Rose Fall 2012 Topic Notes: Conditional Execution All of our programs so far have had one thing in common: they are entirely sequential.

More information

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 Contents 1 Exceptions and How They Work 1 1.1 Update to the Banking Example.............................

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

The compiler is spewing error messages.

The compiler is spewing error messages. Appendix B Debugging There are a few different kinds of errors that can occur in a program, and it is useful to distinguish between them in order to track them down more quickly. Compile-time errors are

More information

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

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15 Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL

More information

Lecture Notes on Memory Layout

Lecture Notes on Memory Layout Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,

More information

DECISION STRUCTURES: USING IF STATEMENTS IN JAVA

DECISION STRUCTURES: USING IF STATEMENTS IN JAVA DECISION STRUCTURES: USING IF STATEMENTS IN JAVA S o far all the programs we have created run straight through from start to finish, without making any decisions along the way. Many times, however, you

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

Assignment 1. Application Development

Assignment 1. Application Development Application Development Assignment 1 Content Application Development Day 1 Lecture The lecture provides an introduction to programming, the concept of classes and objects in Java and the Eclipse development

More information

CS 134 Programming Exercise 9:

CS 134 Programming Exercise 9: CS 134 Programming Exercise 9: Nibbles Objective: To gain experience working with 2 dimensional arrays. The Problem Nibbles is a snake. Nibbles moves around a field, looking for food. Unfortunately, Nibbles

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

Symbol for Windows Shuffle

Symbol for Windows Shuffle Handicom Symbol for Windows Shuffle (Version 4) Handicom, 2011, The Netherlands Content 1. Introduction...2 1.1 What is Shuffle?...2 1.2 System requirements...2 1.3 Installation...2 2. Open, save and play

More information

Creating Java Programs with Greenfoot

Creating Java Programs with Greenfoot Creating Java Programs with Greenfoot Using Randomization and Understanding Dot Notation and Constructors 1 Copyright 2012, Oracle and/or its affiliates. All rights Overview This lesson covers the following

More information

Programming assignment A

Programming assignment A Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in

More information

Programming Exercise

Programming Exercise Programming Exercise Nibbles Objective: To gain experience working with 2 dimensional arrays. The Problem Nibbles is a snake. Nibbles moves around a field, looking for food. Unfortunately, Nibbles is not

More information

Static Methods. Why use methods?

Static Methods. Why use methods? Static Methods A method is just a collection of code. They are also called functions or procedures. It provides a way to break a larger program up into smaller, reusable chunks. This also has the benefit

More information

Computer Science 136 Assignment 2 Mazes Due: Monday, at noon.

Computer Science 136 Assignment 2 Mazes Due: Monday, at noon. Computer Science 136 Assignment 2 Mazes Due: Monday, at noon. This week we are going to develop some classes that allow us to experiment with mazes. All of these classes share a common interface: the participant

More information

Goals of this Lecture

Goals of this Lecture C Pointers Goals of this Lecture Help you learn about: Pointers and application Pointer variables Operators & relation to arrays 2 Pointer Variables The first step in understanding pointers is visualizing

More information

2.4 Choose method names carefully

2.4 Choose method names carefully 2.4 Choose method names carefully We ve already discussed how to name a class in Section 1.1. Now it s time to name methods properly. I m suggesting this simple rule of thumb: builders are nouns, manipulators

More information

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Introduction to Programming Language Concepts

More information

Chapter 2. Basic Operations. you through the routine procedures that you will use nearly every time you work with SPSS.

Chapter 2. Basic Operations. you through the routine procedures that you will use nearly every time you work with SPSS. 1 Chapter 2 Basic Operations Chapter 1 presented a very conceptual overview of SPSS. The present chapter will walk you through the routine procedures that you will use nearly every time you work with SPSS.

More information

CDs & DVDs: Easily Share Documents and Photos

CDs & DVDs: Easily Share Documents and Photos CDs & DVDs: Easily Share Documents and Photos C 204 / 1 Copy Files to CDs & DVDs to Share with Friends and Family Let s say you ve been researching your family history, and over the months you ve collected

More information

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen

Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System

Create a Login System in Visual Basic. Creating a login system. Start a new visual basic Windows Forms application project. Call it Login System Creating a login system Start a new visual basic Windows Forms application project Call it Login System Change the form TITLE from Form1 to Login System Add the following to the form Component Text Name

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

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

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM This assignment focuses on classes and objects. Turn in Ant.java, Bird.java, Hippo.java, Vulture.java,

More information

Part 2: The Material PART 2

Part 2: The Material PART 2 PART 2 With the introduction of what an object is, now we are ready to learn the CONSTRUCTOR concept. Just to refresh our memory, let s take a look at what we have learned in part 1. A sample class declaration,

More information

Creating and Using File Folders

Creating and Using File Folders Creating and Using File Folders ~ 1 ~ Creating and Using File Folders Introduction: File Folders are named storage areas which we create in our computers to keep any documents, pictures, music, videos

More information

Making use of other Applications

Making use of other Applications AppGameKit 2 Collision Using Arrays Making use of other Applications Although we need game software to help makes games for modern devices, we should not exclude the use of other applications to aid the

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

5. Control Statements

5. Control Statements 5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements

More information

Building a safe and secure embedded world. Testing State Machines. and Other Test Objects Maintaining a State. > TESSY Tutorial Author: Frank Büchner

Building a safe and secure embedded world. Testing State Machines. and Other Test Objects Maintaining a State. > TESSY Tutorial Author: Frank Büchner Building a safe and secure embedded world Testing State Machines and Other Test Objects Maintaining a State > TESSY Tutorial Author: Frank Büchner Topic: TESSY is especially well-suited for testing state

More information

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Errors. Lecture 6. Hartmut Kaiser  hkaiser/fall_2011/csc1254.html Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with

More information

Bouml Tutorial. The tutorial must be read in order because I will not repeat each time the general commands to call a menu etc...

Bouml Tutorial. The tutorial must be read in order because I will not repeat each time the general commands to call a menu etc... of 30 11/04/2008 19:18 Bouml Tutorial This tutorial is written to help you to use BOUML for the first time, only few features of BOUML are exposed here, but a fu description of BOUML is given in the reference

More information

A Tutorial for Adrift, Version 5

A Tutorial for Adrift, Version 5 A Tutorial for Adrift, Version 5 Since Adrift is probably the fastest way for students to get their own IF stories up and running, we offer this rather lengthy tutorial. Adrift Developer costs nothing

More information

Microsoft Excel 2007 Lesson 7: Charts and Comments

Microsoft Excel 2007 Lesson 7: Charts and Comments Microsoft Excel 2007 Lesson 7: Charts and Comments Open Example.xlsx if it is not already open. Click on the Example 3 tab to see the worksheet for this lesson. This is essentially the same worksheet that

More information

CS112 Lecture: Loops

CS112 Lecture: Loops CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.

More information

Major Assignment: Pacman Game

Major Assignment: Pacman Game Major Assignment: Pacman Game 300580 Programming Fundamentals Week 10 Assignment The major assignment involves producing a Pacman style game with Clara using the Greenfoot files that are given to you.

More information

Chapter 5 Errors. Bjarne Stroustrup

Chapter 5 Errors. Bjarne Stroustrup Chapter 5 Errors Bjarne Stroustrup www.stroustrup.com/programming Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications,

More information

Marking Period 1. Marking Period 2

Marking Period 1. Marking Period 2 DEPARTMENT: Mathematics COURSE: Programming Through Games & Simulation Week Marking Period 1 1 Intro to Greenfoot 2 Little Crabs 3 Little Crabs 4 Fishing the Crab Game 5 Fishing the Crab Game 6 Fat Cat

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

Crafting Simulated Worlds of Interactive Text: The Basics of Twine for History, English, and Language Teachers

Crafting Simulated Worlds of Interactive Text: The Basics of Twine for History, English, and Language Teachers Crafting Simulated Worlds of Interactive Text: The Basics of Twine for History, English, and Language Teachers Version 1.0: 1/9/2017 Jeremiah McCall: gamingthepast.net @gamingthepast jmc.hst@gmail.com

More information

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 Due: Wednesday, October 18, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 In this week s lab, you will write a program that can solve

More information

Controls Structure for Repetition

Controls Structure for Repetition Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Chapter 1: First Steps to Greenfoot 1

Chapter 1: First Steps to Greenfoot 1 Chapter 1: The first steps Topic: Programming Page: 1 Chapter 1: First Steps to Greenfoot 1 Start Greenfoot. (If you open Greenfoot for the first time, a dialog box that asks what you want. Click on choose

More information

Topic Notes: Java and Objectdraw Basics

Topic Notes: Java and Objectdraw Basics Computer Science 120 Introduction to Programming Siena College Spring 2011 Topic Notes: Java and Objectdraw Basics Event-Driven Programming in Java A program expresses an algorithm in a form understandable

More information

School of Computer Science CPS109 Course Notes Set 7 Alexander Ferworn Updated Fall 15 CPS109 Course Notes 7

School of Computer Science CPS109 Course Notes Set 7 Alexander Ferworn Updated Fall 15 CPS109 Course Notes 7 CPS109 Course Notes 7 Alexander Ferworn Unrelated Facts Worth Remembering The most successful people in any business are usually the most interesting. Don t confuse extensive documentation of a situation

More information

CS 2110 Summer 2011: Assignment 2 Boggle

CS 2110 Summer 2011: Assignment 2 Boggle CS 2110 Summer 2011: Assignment 2 Boggle Due July 12 at 5pm This assignment is to be done in pairs. Information about partners will be provided separately. 1 Playing Boggle 1 In this assignment, we continue

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

Computer Programming. Basic Control Flow - Decisions. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Decisions. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Decisions Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To be able to implement decisions using if statements To learn

More information

ASSIGNMENT 4 Records and Objects

ASSIGNMENT 4 Records and Objects ASSIGNMENT 4 Records and Objects COMP-202B, Winter 2010, All Sections Due: Wednesday, March 31, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all

More information

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Note. The above image and many others are courtesy of   - this is a wonderful resource for designing circuits. Robotics and Electronics Unit 2. Arduino Objectives. Students will understand the basic characteristics of an Arduino Uno microcontroller. understand the basic structure of an Arduino program. know how

More information

CS112 Lecture: Defining Instantiable Classes

CS112 Lecture: Defining Instantiable Classes CS112 Lecture: Defining Instantiable Classes Last revised 2/3/05 Objectives: 1. To describe the process of defining an instantiable class 2. To discuss public and private visibility modifiers. Materials:

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Word for Research Writing I: Text and Structure

Word for Research Writing I: Text and Structure Word for Research Writing I: Text and Structure Last updated: 10/2017 Shari Hill Sweet dteditor@nd.edu or 631-7545 1. The Graduate School Template...1 1.1 Document structure... 1 1.1.1 Beware of Section

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 9 Date:

More information

MICROSOFT Excel 2010 Advanced Self-Study

MICROSOFT Excel 2010 Advanced Self-Study MICROSOFT Excel 2010 Advanced Self-Study COPYRIGHT This manual is copyrighted: S&G Training Limited. This manual may not be copied, photocopied or reproduced in whole or in part without the written permission

More information

For this class we are going to create a file in Microsoft Word. Open Word on the desktop.

For this class we are going to create a file in Microsoft Word. Open Word on the desktop. File Management Windows 10 What is File Management? As you use your computer and create files you may need some help in storing and retrieving those files. File management shows you how to create, move,

More information

Problem Solving through Programming with Greenfoot. Mark Lewis

Problem Solving through Programming with Greenfoot. Mark Lewis Problem Solving through Programming with Greenfoot Mark Lewis February 24, 2017 Preface There are two significant goals of this text: to teach basic programming skills and to improve students problem solving

More information

CS193P: HelloPoly Walkthrough

CS193P: HelloPoly Walkthrough CS193P: HelloPoly Walkthrough Overview The goal of this walkthrough is to give you a fairly step by step path through building a simple Cocoa Touch application. You are encouraged to follow the walkthrough,

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Exercise 4: Loops, Arrays and Files

Exercise 4: Loops, Arrays and Files Exercise 4: Loops, Arrays and Files worth 24% of the final mark November 4, 2004 Instructions Submit your programs in a floppy disk. Deliver the disk to Michele Zito at the 12noon lecture on Tuesday November

More information

Section 1.3 Adding Integers

Section 1.3 Adding Integers Section 1.3 Adding Integers Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Represent integers as vectors. The integer number line (1.2) Add

More information

1 Inheritance (8 minutes, 9 points)

1 Inheritance (8 minutes, 9 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Exam 2, 6 April, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight.

More information

Telling a Story Visually. Copyright 2012, Oracle. All rights reserved.

Telling a Story Visually. Copyright 2012, Oracle. All rights reserved. What Will I Learn? Objectives In this lesson, you will learn how to: Compare and define an animation and a scenario Demonstrate how to use the four problem solving steps to storyboard your animation Use

More information

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style

More information

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false. CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in

More information

An Overview of Visual Basic.NET: A History and a Demonstration

An Overview of Visual Basic.NET: A History and a Demonstration OVERVIEW o b j e c t i v e s This overview contains basic definitions and background information, including: A brief history of programming languages An introduction to the terminology used in object-oriented

More information

Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)

Assignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00) Assignment 4 Aggregate Objects, Command-Line Arguments, ArrayLists COMP-202B, Winter 2011, All Sections Due: Tuesday, March 22, 2011 (13:00) You MUST do this assignment individually and, unless otherwise

More information

Lecture 10: Lindenmayer Systems

Lecture 10: Lindenmayer Systems Carl Kingsford, 0-01, Fall 015 Lecture 10: Lindenmayer Systems (Stacks, Queues, append, and list literals) Lindenmayer systems or L-systems are a way to model complex shape contruction simply. They are

More information

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup. Chapter 5 Errors Hyunyoung Lee Based on slides by Bjarne Stroustrup www.stroustrup.com/programming 1 Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must

More information