RoadMap: You will begin today programming something you already know how to do in a language you already know. Then you will do some "real" programs in the same language, then the same programs in Java (because you already know how they work), and finally some of the same programs with full graphics. Then you will be ready to write anything you want. You can do this, but it will take time. Stay with us and we will get you there at your own pace.
Video Introduction
(10 minutes) <<--- Watch this video first, then
English IDE<<--- Click this link and write your first program here.
When it runs correctly (without errors or warnings)
click the yellow Done button.
Then come back here and click thisNext
link to skip down to the next video.
If it's not a link yet, you might need to refresh your browser, or else click this button to call a mentor:
If you are like me and prefer to read at your own pace instead of whatever pace set in some video, You can read the transcript (and probably come out ahead of the non-readers).Additional discussion, not in the video.
Not everybody eats peanut butter & jelly sandwiches, but it's reasonably healthy (balanced protein) and pretty much everybody knows how to make a PBJ, even if you have more fun things to eat most of the time. So it's a program that you can write and another person -- or (today) a computer -- can run to make a PBJ.
The most important part of programming is understanding -- in English (or Spanish or Chinese, whatever language you think in) -- what the program does. Start with one line, like a title:
Make Peanut Butter and Jelly Sandwich
There, in one line is our program. It doesn't say how to
make a PBJ, only what it is you want to do. The computer still needs to
know how, which (today) we do in English. Later we will do some of the
same programs in Java. But thinking comes first.
So let's talk about how. It involves a sequence of steps, which we do in a "Integrated (Program) Development Environment" (IDE). Click this button to open our "Integrated Development Environment" in a new window, which you can position to one side or above or below the instructions in this page:
At the top is a place for you to type in your Zoom name. If you do that, then this IDE will save your program for you from day to day, and eventually (not today) it will be able to automatically summon a Mentor to help you if you get stuck. Until that happens, you need to click the MentorAlert button (here below or in the IDE, but it needs your Zoom name) or the "Ask" button on the Zoom window. But saving your work is a good thing, so put your name there now.On the left side is a panel for you to type program lines into. On the right side is where the output happens. At the bottom is an alphabetical list of what you can tell the computer to do in making a PBJ. The program panel is blank -- if not, your Zoom name is already used by another student, click the New button to add some digits guearanteed to make it unique -- Anyway, the program panel comes next.
A computer program -- and our program to make a PBJ -- is a sequence of steps. First you walk into the kitchen (where the food is)... This computer doesn't walk, but it can (let you) see:
see the kitchenStart by typing this line into the program panel, then click Run. It opens up a view into the "Kitchen Computer" that will run your sandwich program. This doesn't make a sandwich, it just shows you what the kitchen looks like.
OK, we saw the kitchen, we can delete that line. It will automatically show the kitchen when we do anything there, like making our sandwich.
When you tell somebody how to make a PBJ, you might give them a long list of instructions, but they will understand you better if you start off simple. Start with the name -- we put it quotes to tell people (and in this case, the computer) that this is the name of what we are about to do:
"make pbj"
Then you get the necessary stuff out of the cabinets or wherever
it is, then you put it together. Like this:
"make pbj"
get stuff
put it together
done
This is how you make every program you will ever write: first you
tell the computer the name of what to do, and then you tell the computer
how to do it! It's called "Top-Down Design" and it's so important, we will
repeat it a lot. Now, let's repeat our two steps process again: What do
we want to do? Get the stuff. That becomes the name of the part of the
program to tell the computer how to get the stuff:
"get stuff"
Then we fill in how to get the stuff. In this case we need the ingredients
and the utensils, followed by the rest of the program we already have,
plus a line to get it started:
"get stuff"
get ingredients
get tools
done"make pbj"
get stuff
put it together
donedo make pbj
So how does the computer (or person) get the ingredients for a PBJ?
This computer knows what it needs, but when you graduate to Java later
this term, the computer knows nothing at all, except what you (or somebody
else) told it. That's true of the Sandwich computer too, except I already
told it how to make a PBJ. Now you get to replace (some of) what I did
with your own program. Did you see what it did? It got out bread and jam
and peanut butter. Let's make it more computer-ish:
"get ingredients"
get bread
get jam
get PB
done"get stuff"
get ingredients
get tools
done"make pbj"
get stuff
put it together
done
I bet you can do the same thing with the utensils -- I mean tools:
In English we have a lot of words that mean the same thing (and the Sandwich
computer knows some of those synonyms), but when you give a name to something
in your program, you must spell it exactly the same everywhere.
It doesn't even need to be a real English word, once you tell the computer
what the name is, it's like you invented a new word, and it means exactly
what you tell the computer it means, nothing more, nothing less.
So why don't you do that? You want to write a new piece of the program to get the tools we need (the knife and plate). It will look something like the "get ingredients" except it will have a different name is quotes, and get different things. [Then after you see that it still makes a PBJ, click the Done button.]
Video Part 2: Finish(5 minutes) <<--- Watch this video next, and/or keep reading...
Make Peanut Butter and Jelly SandwichOnly for Google you must do it in Java or C or Python, so you need to write all the parts too. Use Top-Down Design -- you already have the first layer, and you already have the bottom details for the ingredients and the utensils. Today you don't need to do it in Java or C or Python, you just need to write all the parts in the Sandwich version of English (you can see everything you need in the Quick Reference section at the bottom of the Sandwich IDE page).
Yes, it's a lot of detail work, but that's what programming is: a few flashes of brilliant insight (that's the "Top" part of Top-Down Design, which we already did for you, and you will get to do more as we get farther into this), and mostly tedious detail work at the bottom of the "Down" part. You should try it this first week, but if it's not your cup of tea, that's OK, find something else that interests you.
You will know you have succeeded when all of the "Assume..." messages are gone. They are there when you use my code instead of your own. You can get rid of them. Mostly they hint at lines you can copy from the Quick Reference section at the bottom of the Sandwich IDE page. But you need to put them in the right order, or it won't make your sandwich at all.
Getting things in the right order is an important idea of computer programming. We call it Sequence, and it's one of six basic concepts, which when you understand all six, you can write any program at all, in any programming language.
The Top-Down Design principle (giving a name to what you want to do, then spelling out how you want to do it) is another important concept, which we call Subroutines. We'll have more to say about subroutines as we go along, but already you are a third of the way into everything you need to know about programming. Except for the details, there are tons of details, but if you keep the Big Ideas in mind, the details come easier.
So make your PBJ without any "Assume..." messages. It's a couple dozen lines of added code, and then it's your program! You can't do it all at once, but you can do it. If you get stuck, that's what the Mentors are for (click this button to get help)
One detail I need to mention, this is a new development environment,
not everything works properly. When you add lines that get rid of assumptions,
you need to be careful that they are in the right order, getting things
must be earlier in the program than opening them, which must be earlier
than using them, and so on. Otherwise it just fails to do anything at all.
Congratulations! Your program ran correctly. Click this link to advance to the next segment: Conditionals & Input
[2022 September 2]