Intro to Computing - Lab 01

Tuesday, January 13th

Objectives:


Part A: Completing some additional questions

Yesterday I asked you to complete a fairly short information sheet.  I actually have a number of things I would like you to respond to but we just don't have enough time on the first day of class.  To get started today, please complete my "Getting to Know You" the long version (I will give you a paper copy of this in class).


Part B: Logging on and Setting up

Logging on to the CNS network

  1. Locate a free computer in Wright 112 (these same procedures will work in the lab in Wright 339)

  2. The computers in this lab are “dual boot” - that is, they run both Windows and Linux. We will be using the Windows side of things. If you happen to sit at a computer that is booted into Linux then you will need to reboot the machine into Windows (You will know you are in Linux if the login screen is titled “GNOME Desktop Manager). To reboot the machine

  1. Once you are sitting at a computer that is booted into Windows, you will need to log on:

Creating a directory for this class

In order to keep your files for this course together and in a place where they can be easily accessed from multiple locations, you will want to create a couple of folders for your course materials.

  1. Open up the graphical representation of the computer by selecting "Start | My Computer " or selecting My Computer from the desktop

  2. Select (double click) on the icon for the network drive named “Math-CS” that should be towards the bottom of this window.

  3. When this drive opens up notice that the address field says “P:\” For this reason I will refer to this as the “p drive” (tricky, I know!)

  4. Select the icon labeled “810-051-schafer” This is the directory for this course.

  5. Select the icon for the folder labeled with your username.

  6. Create a new folder in this directory and give it the name mediasources.  You can do this by right clicking in the empty area and selecting “New | Folder” and then renaming the folder that is created.

  7. Use the "Back" button to return to examining the contents of the course directory.

  8. Select the directory labeled “common”

  9. COPY the two files from this common directory (logo.jpg and fanfare.wav) and paste them into the mediasources directory you just created in step 6. Again, please COPY these files so everyone has access to them.

  10. Now you should be ready to explore one of the main tools we will use this semester - JES.


Part C: Using JES as a Tool

During this course you will use JES (Jython Environment for Students) as a tool to explore programming.  JES is a free IDE (Integrated Development Environment) of the Python programming language which includes a library of some non-standard Python commands to manipulate media files based on the materials in your textbook.  While you will not explore ALL of JES during today's lab, we want to get started so you have a little bit of a feel for how things work.

  1. Launch JES by selecting "Start | All Programs |  Programming | JES 3.1 | JES"
  2. The first time you do this you may encounter one or more boxes asking you for registration information for an email based submission system that we will not use.  Therefore, you may select "ok" or "cancel" as appropriate to skip through these screens. 

When JES is finally fully loaded it should look like this:

JES has two main ways to write code (we call instructions for the computer "source code" or simply "code for short). 

The top part of JES is the "Program Area"  This is where you write code that you want to keep.  The Program Area lets you write code, store it to a file, and load it from a file later on.  It behaves like a very simple text editor (like Notepad or Microsoft Word).  While we will use this area extensively during this course, we will not use it very much in today's lab.

The bottom part of JES is the "Interactions Area"   This is where you write code when you are just trying stuff out and trying to see what things do.  Since this is the main point of today's lab, we will use this area today.


Hello World from the interaction pane

While this following example program is incredibly outdated, there is a traditional/historical first program, often referred to as "Hello World"  It's purpose - to simply print a simple message to the computer screen.  Your texbook shows the way this might be done in several different languages on page 6.  Because we are using JES and an interactions pane, we can make this even easier than the code described on page 6.

In the interactions area (the bottom window) type the following:

print "Hello World!"

When you hit Enter, JES goes off to interpret what commands you gave it.  In this case, it interprets your command as an instruction to print (to the screen, not the printer) whatever message is included inside of the quotes (in computer vocabulary we normally refer to the message between quotes as a String).


Syntax Errors

Of course, if you typed something into the interactions pane that JES doesn't recognize, you will get an error message.  To demonstrate this, type:

prin "Hello World!"

(notice that I mis-spelled print).  This gives you a message that should say something like:

Whenever you get a message like this, pay close attention to what I ASKED you to type and what you ACTUALLY typed.  While sometimes I might have a mistake in my lab, more often, you will have made a typo.


Playing around a little bit

Ok, all of that was pretty boring.  Let's personalize it a little bit.  Try typing in:

print "Hello Ben!"

(of course, you should replace MY name with your name so that you print "Hello Jeffrey" or "Hello Samantha" or "Hello Karl" or whatever is appropriate for you).

 

[Q1]  Now, what do you think will happen if you type in the following:

print "Hello" + "Ben"

SideBar:  Frequently during labs you will see a special designation contained inside of square brackets like the [Q1] above.  In this instance, this indicates that I have asked you question #1.  This will correspond to a paper lab sheet that you will complete while you are in lab and submit as part of the credit for being in lab and completing the activities.  You should ALWAYS stop what you are doing and answer the question(s) before moving on.  For example, you should stop and answer this question BEFORE you type it into the computer.


 

[Q2]  Try it.  Did you guess right?  Look closely.  Exactly right???

 

Notice that python (like many languages) allows you to use the plus symbol (+) when dealing with Strings.  When you "add" to Strings together you perform "concatenation"

 

[Q3]  What would you need to modify in this command to have it print the way we expect it to be printed?  Try it out and make sure that you are correct.

 

[Q4]  What do you predict will happen when you type

print "3 + 2"

[Q5]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q6]  What do you predict will happen when you type

print 3 + 2

[Q7]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q8]  What do you predict will happen when you type

print "3" + "2"

[Q9]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q10]  What do you predict will happen when you type

print "3" + 2

[Q11]  Try it.  Were you correct?  If not, what was printed?  What does this mean?

 

 

[Q12]  What do you predict will happen when you type

sum = "3" + "2"
print sum

[Q13]  Try it.  Were you correct?  If not, what was printed?  What does this mean?

 


Making sure that JES will work with image files

One of the other things that we talked about in lecture yesterday is the fact that we will be focusing on media computation this semester - the manipulation of sound and image files.  While we will do a lot of this later on this semester, I want to make sure that we aren't going to have any surprised when the time comes.  Let's make sure that your account and JES will open and "show" picture and sound files.

Type the following into the interactions pane

filename = pickAFile()

After a few moments a standard file chooser pop up should appear.  Using this, select the file "logo.jpg" that you saved onto your computer earlier in the lab.  Once this is done, type:

print filename

[Q14]  What happens when you type print filename?  What does this represent?

 

Now type:

picture = makePicture(filename)
print picture

[Q15]  What happens when you type print picture?  What does this represent?

 

Finally, type:

show(picture)

A small UNI logo should appear on your screen.  If it does not, please talk to an instructor.

 


Making sure that JES will work with sound files

Type the following into the interactions pane

filename = pickAFile()

Select the file "fanfare.wav" that you saved onto your computer earlier in the lab.  Once this is done, type:

print filename

[Q16]  What happens when you type print filename?  What does this represent?

Now type:

sound = makeSound(filename)
print sound

[Q17]  What happens when you type print sound?  What does this represent?

If you happen to have headphones with you, you can plug them into the headphone jack on the front of the computer and type

play(sound)

A small trumpet fanfare should be played over your headphones.  If it does not, please talk to an instructor.


Part D: Details about this class

If you have not already done so, use the web browser of your choice to navigate to the course website (www.cs.uni.edu/~schafer/courses/051).  Follow the link for the "Original Syllabus."  (You were given a paper copy of this in class on Monday).  While reading the syllabus, answer the following questions.

 

[Q18]  What is the email address for the class mailing list?

[Q19]  What is the minimum grade you need to earn in this class if you want to take data structures (CS II)?

[Q20]  Approximately how many points will you earn over the course of the semester?  How many of these are assigned during exams?

[Q21]  What is the URL for the University’s Academic Conduct policy?

 

I also post lecture notes to the website when appropriate.  On Monday I used Power Point slides in class.  These slides are posted to the website as well.  Open the slides from Monday and search for the following information.

 

[Q22]   What is the name of the cartoon character with the power drill?

 


Part E: Exploring Binary

While we will spend most of class on Wednesday and Friday exploring binary and data representation in the computer, you can learn a little bit about binary just by exploring on your own.  Play with the applet below and answer the questions that follow.

You do not have a Java enabled browser

 

[Q23]  Press the button labeled "1".  What things changed in the applet window?

[Q24]  Press the button labeled "8".  What things changed in the applet window?

[Q25]  Press the button labeled "1" again.  What things changed in the applet window?

[Q26]  Press several buttons of your choice.  After each button press consider what has changed.  How would you describe the general behavior of this applet?

[Q27]  Without doing it, suppose that you were to press the appropriate buttons so that the sequence of 1s and 0s reads "00001100"  What value do you PREDICT would be displayed in the applet?

[Q28]  Try it.  Were you correct?

[Q29]  Predict what value would be displayed if you set the sequence to read "00001111" 

[Q30]  Try it.  Were you correct?

[Q31]  Predict what value would be displayed if you set the sequence to read "10001111" 

[Q32]  Try it.  Were you correct?

[Q33]  Predict what value would be displayed if you set the sequence to read "11111111" 

[Q34]  Try it.  Were you correct?

[Q35]  What sequence of 1s and 0s do you predict you would you need to produce a value of 11?

[Q36]  Enter that sequence.  Were you correct?  If not, what sequence does produce a value of 11?

[Q37]  What sequence of 1s and 0s do you predict you would you need to produce a value of  73?

[Q38]  Enter that sequence.  Were you correct?  If not, what sequence does produce a value of 73?

[Q39]  What sequence of 1s and 0s do you predict you would you need to produce a value of  173?

[Q40]  Enter that sequence.  Were you correct?  If not, what sequence does produce a value of  173?

 


Finishing Up

At this point you should check over your activity report to make sure that you have answered all questions.  Once you are sure it is complete, you should turn it in and you are free to leave. 

 

Do not forget to "log off" of the machine you are working on.