18
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003– 2004; modified by Robert H. Sloan & Pat Troy, University of Illinois at Chicago, 2005, for educational use.

CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Embed Size (px)

Citation preview

Page 1: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

CS 100Introduction to Computing

Introduction to JES

Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan & Pat Troy, University of Illinois at Chicago, 2005, for educational use.

Page 2: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Installation Installing JES and starting it up

Windows users: Just copy the folder from the CD Double-click JES application

Mac OS X users: Just drag (i.e., copy) JES from Mac folder into your Applications Double-click JES application

Enter a blank in the form for turnin (we probably won’t use) There is always the Help Menu (Take a look at it)

Lots and lots of excellent help

Page 3: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

We will program in JES

JES: Jython Environment for Students A simple editor (for entering in our programs):

We’ll call that the program area A command area for entering in commands for

Python to execute.

Page 4: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

JES - Jython Environment for Students

Program Area

Command Area

Page 5: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Tour of JES

Save and Save As Cut/Copy/Paste with shortcut keys Turnin

TA will give instructions for submitting your Jython This will start with Lab 10; they’re in the lab

Help Explain is contextualized help: Highlight a JES (media) function Lots of help on mediatools and the like

Page 6: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Python understands commands

We can name data with “=” (assignment operator)

We can print values, expressions, anything with print

Page 7: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Using “print” in JES

>>> print 34 + 5690>>> print 34.1/46.50.7333333333333334>>> print 22 * 33726>>> print 14 - 15-1>>> print ”Hi"Hello>>> print ”Hi" + ”Bob!"HiBob!

Page 8: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Command Area Editing

Up/down arrows walk through command history You can edit the line at the bottom

Just put the cursor at the end of the line before hitting Return/Enter.

Page 9: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Demonstrating JES for files and sounds>>> print pickAFile()/Users/guzdial/mediasources/barbara.jpg>>> print makePicture(pickAFile())Picture, filename /Users/guzdial/mediasources/barbara.jpg height 294 width 222>>> print pickAFile()/Users/guzdial/mediasources/hello.wav>>> print makeSound(pickAFile())Sound of length 54757>>> print play(makeSound(pickAFile()))None>>> myfilename = pickAFile()>>> print myfilename/Users/guzdial/mediasources/barbara.jpg>>> mypicture = makePicture(myfilename)>>> print mypicturePicture, filename /Users/guzdial/mediasources/barbara.jpg height 294 width 222>>> show(mypicture)

Page 10: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Writing a recipe: Making our own functions To make a function, use the

command def Then, the name of the

function, and the names of the input values between parentheses (“(input1)”)

End the line with a colon (“:”) The body of the recipe is

indented (Hint: Use two spaces) That’s called a block

Page 11: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Making functions the easy way

Get something working by typing commands Enter the def command. Copy-paste the right commands up into the recipe

Page 12: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

A recipe for playing picked sound files

def pickAndPlay(): myfile = pickAFile() mysound = makeSound(myfile) play(mysound)

Note: myfile and mysound, inside pickAndPlay(), are completely different from the same names in the command area.

Page 13: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

Blocking is indicated for you in JES

Statements that are indented the same, are in the same block.

Statements that are in the same block as where the line where the cursor is are enclosed in a blue box.

Page 14: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

A function for playing picked picture files

def pickAndShow(): myfile = pickAFile() mypict = makePicture(myfile) show(mypict)

Page 15: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

The Most Common JES Bug:Forgetting to Load Your function does NOT exist for JES until you

load it Before you load it, the program is just a bunch of

characters. Loading encodes it as an executable function

Save and Save As You must Save before Loading You must Load before you can use your function

Page 16: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

What if you forget your variable names? showVars()

Page 17: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

JES - Help Menu

The help menu is very very useful. Before you start, make sure you take a look at Getting Started with JES and Programming in Jython.

Page 18: CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan

MOST IMPORTANT THING TO DO TO PASS THIS CLASS! DO THE EXAMPLES! Try them out for yourself. Try to replicate them.

Understand them EVERY WEEK, TYPE IN AT LEAST TWO OF THE EXAMPLES FROM

CLASS and/or THE TEXTBOOK

To understand a program means that you know why each line is there.

You will encounter all the simple-but-confusing errors early—BEFORE you are rushing to get homework done!!