Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Using Jeroo Dianne Meskauskas
Nested If Statements While Loops
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
11-May-15 Control Structures part 2. Overview Control structures cause the program to repeat a section of code or choose between different sections of.
Conditionals How do we solve tasks in which every particular of a task is not specifically known? – A robot needs the ability to survey its immediate environment.
Program Design and Development
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Chapter 3 Planning Your Solution
10-1 Programming Remember: –programming language –how to program (conceptually) –intro to programming the “ROBOT” computer In this lecture: –programming.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
Chapter 5 Conditionally Executing Instructions
17-Sep-15 Using Jeroo. Overview In this presentation we will discuss: What is Jeroo? Where did it come from? Why use it? How it works. Your first assignments.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
5-Oct-15 Introduction and Code. Overview In this presentation we will discuss: What is Jeroo? Where can you get it? The story and syntax of Jeroo How.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
CPS120 Introduction to Computer Science Iteration (Looping)
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
25-Oct-15 Jeroo Code. Overview In this presentation we will discuss: How to write code in Jeroo How to run a Jeroo program.
CPS120: Introduction to Computer Science Decision Making in Programs.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Recursion – means to recur or to repeat – A different way to get a robot to repeat an action A programming language that allows recursive definitions (and.
13-Nov-15 Control Structures. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
Algorithm Design.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
1 CS161 Introduction to Computer Science Topic #9.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
16-Dec-15 Control Structures VB. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
CPS120 Introduction to Computer Science Iteration (Looping)
Java Programming Fifth Edition Chapter 5 Making Decisions.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Karel J. Robot Chapter 6 Instructions That Repeat.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Alice and Java Unit 7 1. Day 1  Objective: Gain an introduction to Java and Eclipse  Essential skill: DM-1: Use technology to advance critical thinking.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
CS 106A, Lecture 3 Problem-solving with Karel
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Control Structures part 2
Basics of Computer Programming
Loops BIS1523 – Lecture 10.
Eric Roberts and Jerry Cain
Jeroo Code 18-Jul-18.
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Karel – Primitive Instructions
Understand Problem Solving Tools to Design Programming Solutions
Basics of Computer Programming
Basics of Computer Programming
Basics of Computer Programming
The structure of computer programs
Creativity in Algorithms
slides courtesy of Eric Roberts
Introduction and Code 18-Jan-19.
Control Structures 5-Apr-19.
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
Control Structures part 2
Basic Concepts of Algorithm
Control Structures 12-May-19.
Control Structures VB part 2
IF 1-Jul-19.
Jeroo Code 7-Sep-19.
Presentation transcript:

Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department

For Tuesday `Read Savitch 1.4 `Practice problems 22-27

Questions? `Any questions about last class or material covered on Tuesday?

What is Jessica? `Jessica is a simple programming language developed by Dr. Mary Elaine Califf, an instructor in the ACS department here at ISU. `It is an easy to learn language that will allow us to jump into programming with very little instruction.

Who is Jessica? `Jessica is something not entirely unlike a kangaroo `She lives on the island of Santong, a rather strange perfectly square island `Jessica cannot swim--if she jumps off the island, she’ll drown `Jessica’s home is in the far northwest corner of the island `The island has two objects on it besides Jessica: nets and flowers `If Jessica moves onto a net, she is caught and presumably killed

What Can Jessica Do? `She can hop forward -- hop; `She can turn left exactly 90 degrees -- left; `She can turn right exactly 90 degrees -- right; `She can pick a flower she’s standing on top of -- pick; `She can toss a flower into the space in front of her (done to destroy a net) -- toss;

Jessica Programs /* Always begin every program with a comment including your name */ void main()/* no spaces between n and ( */ { /* brace is required */ /* instructions go here */ hop; right; hop; } /* end program -- brace is required */

Instructions `hop - move forward one unit `left - turn left 90 degrees `right - turn right 90 degrees `pick - pick a flower `toss - toss a flower forward one unit; any net there is disabled; the flower disappears whether there’s a net or not

Controlling Jessica `If we know EXACTLY what Jessica’s environment looks like and exactly what we want her to do, we can easily write a program to make her do it. `But `We often want to write a more generic program `A program consisting of just the five basic instructions can be very long

Control Structures `To solve this problem, programming languages (including Jessica) provide different control structures. `We use three basic control structures: `sequence `selection `repetition

Sequence `A sequence is a set of instructions in order: `hop; `right; `pick; `We can give Jessica instructions in a specific order, and Jessica will follow those instructions, one at a time, in the order specified.

Selection `Selection is the control structure that allows Jessica to make choices. `For example, we might want her to pick a flower only if she’s standing on one (to keep that annoying message from popping up) or to toss a flower only if there’s a net in front of her (to avoid wasting them)

Selection in Jessica `The selection statement in Jessica looks like this: `if (condition) { statements to do if condition is true } else { statements to do if condition is false }

Repetition `The repetition control structure allows Jessica to repeat the same action(s) more than once. `She stops when some condition in her environment that you specify changes. `For example, if you want Jessica to hop until there is water in front of her, you can use repetition, or a loop, to do that.

Repetition in Jessica `The repetition statement in Jessica looks like this: `while (condition) { statements to repeat } `If condition is false to start with, the statements will never be executed `The condition must be something that will be changed when the statements are executed

Conditions `In both if statements and while loops, we need conditions which can be true or false. `In Jessica, there are 10 conditions that we can test. `These are the 10 things Jessica knows about her environment

What Does Jessica Know? Simple Conditions: at_flower out_of_flowers net_ahead net_on_left net_on_right water_ahead facing_north facing_south facing_east facing_west

Example of Selection if (at_flower) { pick; toss; } else { hop; } Notice the punctuation semicolon (;) after each statement in instruction block no semicolon after if (at_flower) or else

Example of Repetition while (at_flower) { pick; hop; } Notice the punctuation semicolon (;) after each statement in instruction block no semicolon after while (at_flower) braces enclosing instruction block

Negating a condition if (!water_ahead) { hop; } ` NOT:!simple condition opposite of simple condition while (!water_ahead) { hop; }

Programming Practice `Write code to make Jessica: `Hop one space ahead only if there is a net on her left `Pick a flower that is an unknown number of spaces ahead of her `Check for a net in front of her, and, if there is one, disable it by tossing a flower `Face north when you do not know which way she is facing

More Practice `Write code to make Jessica: `Hop one space ahead. If there is a net on the right she, she should turn left; otherwise she should hop an addition space forward. `Disable the net in front of her if she has a flower in her pouch, but go around the net if she does not. Assume Jessica and the net are not adjacent to the water.

Task Lists `A list of the things Jessica is supposed to do `Does not have to be in order `Should be written in plain, clear English

Example `We want to write a fairly simple Jessica program. `The environment setup is: `Jessica is facing in an unknown direction with no flowers in her pouch `There is a flower somewhere north of Jessica `There is a net somewhere north of the flower `Jessica is to use the flower to destroy the net

Task List `Face north `Pick the flower `Go to the flower `Go to the net `Destroy the net

Implementation `Once we’ve considered what Jessica needs to do, writing the program consists of: `Putting the tasks in the correct order `Writing the Jessica code to accomplish each task `Let’s work through implementing this program together.

Task List Practice ` Environment: ` There is a rectangle made of nets. ` Along an inside wall of the rectangle is a flower. ` Jessica is inside the rectangle, with a net on her left. ` Jessica has no flowers in her pouch. ` Task: Jessica is to leave the rectangle.

Modularization `What do we mean by this term? `What is a module? `Why modularize programs?

Why Modularize? `Solving small problems is easy `Solving large, complex problems is hard `The goal of modularization is to break a problem into subproblems that are as independent of one another as possible `If you do this, you only have to solve one of these subproblems at a time

Steps in Modularization `Develop the task list `Group the tasks into modules `Construct structure chart `Consider order of processing `Create logic of the mainline with calls to the major processing modules `Write the modules, working from top to bottom

Paper Program `Jessica is inside a rectangular house. `There is a single door located on one wall. (Jessica is not facing the door.) `Outside the door is a paper (flower). `Help Jessica locate the door, collect the paper, and return to her house.

Write a Task List `Find the wall `Find the door `Go outside `Find the flower `Pick the flower `Return to the house

Structure Chart Example: Jessica Paper Program Morning Paper Find Wall Back Home Find Door Pick Paper

Program Design `What do we mean by the term “program design”? `Why design programs?

Design Tools `What is the first step in designing a program?

Notes on Task Lists `Just a list of the things Jessica is supposed to do `Does not have to be in order `Should be written in plain, clear English

Example `We want to write a fairly simple Jessica program. `The environment setup is: `Jessica is facing in an unknown direction with no flowers in her pouch `There is a flower somewhere north of Jessica `There is a net somewhere north of the flower `Jessica is to use the flower to destroy the net

Task List `Face north `Pick the flower `Go to the flower `Go to the net `Destroy the net

Implementation `Once we’ve considered what Jessica needs to do, writing the program consists of: `Putting the tasks in the correct order `Writing the Jessica code to accomplish each task `Let’s work through implementing this program together.

Task List Practice ` Environment: ` There is a rectangle made of nets. ` Along an inside wall of the rectangle is a flower. ` Jessica is inside the rectangle, with a net on her left. ` Jessica has no flowers in her pouch. ` Task: Jessica is to leave the rectangle.