Download presentation
Presentation is loading. Please wait.
Published byJulie Thomas Modified over 8 years ago
1
CRE Programming Club - Class 3 Robert Eckstein and Robert Heard
2
A Simple Conversation Let’s have a simple conversation with four statements. “Good Morning.” “I like the wind.” “That’s nice.”
3
What Do I Mean? What do we mean by Good Morning? Do we mean, “I am having a good morning?” Or do we mean “I hope you have a good morning?” Or are we excited about the morning and we want to tell everyone about it: “GOOD MORNING!” Am I warning everyone about the “Good morning!” out there? Or do we just mean “Hello.”
4
What Do I Mean? How about: I like the wind (Are we talking about the wind outside, or the act of winding something like a string?) We know it’s the wind because it has a “the” before it, so it’s a noun. But a computer is not (initially) that smart. It has to be told about that rule of the language.
5
What Do I Mean? What if I say, “Oh, yeah! I love to go the store!” or (sarcastically) “Oh, yeah, I love to go to the store.” If I just type those words into a computer, it has no idea which one I mean. It’s the exact same words, but whether or not I really mean it depends on my tone of voice.
6
No Confusion! A computer language must have statements that have no confusion whatsoever. If I say A = 20, then I mean set A to 20. There’s no confusion about that at all. No, “Oh, please set A to 20” No, “If you feel like it, or whenever you get a chance.” When the computer reads the statement, it does what it says… no questions asked.
7
Computer Languages Follow Strict Grammars!
8
Let’s Learn About Objects In the world of programming, objects are very important. In fact, about 25 years ago, they changed programming forever. What’s an object? Well, its easier to explain what an object contains....
9
Properties What are properties? Properties are the variables or the constants that the object has.
10
Operations Operations are things that the object can do, usually with the help of the properties. You can tell an operation as it is always followed by parenthesis.
11
Events Events are things that happen outside our program that it may want to be aware of, such as the mouse moving or clicking, or a key being pressed on the keyboard. You may need to “handle” them.
12
What’s the Difference Between Operations and Events? Operations are something we make happen. Events are something that something else (outside the program) makes happen...and we want to know about it!
13
Let’s Take a Practical Example.... What are some properties of my daughter Lauren: Hair color Age She has two eyes
14
What Are Some Operations? Jump up and down the number of times of your age Brush your hair Tell us how many eyes you have
15
What Are Some Events? She got sick She got hurt on the playground A boy kissed Lauren (I really want to know this!) Remember that events are not operations! Operations are things that our program makes happen. Events happen outside the program, and the program needs to know about them.
16
Bookmark the Docs Look online at TextWindow documentation (Reference Documention on smallbasic.com) Also, did you notice that when you were typing in TextWindow, the Intellisense also tried to guess what you wanted. If you choose TextWindow, it will display all the properties, events, and operations that an object has. So, TextWindow has properties like “Title”. It has operations like “WriteText” and “Read”. It doesn’t have events.
17
Go to smallbasic.com and click on Reference Documentation...
18
Accessing Objects We get ahold of properties, events, and operations by writing the name of the object, followed by a dot, followed by the name of the property, event, or operation. So, for example. Math.PI (constant) TextWindow.Title = “My Program” (variable) TextWindow.writeLine(...) (operation) TextWindow.readLine() (operation) TextWindow.clear() (operation)
19
Operations With operations, we can give information to it by putting it inside parenthesis. In fact, if you look at the object documentation, many operations expect one or more things to be passed to it. On the first day, what did we pass into TextWindow.writeLine()?
20
Operations Some operations will also return something. We can get ahold of it by assigning the return value to a variable. It looks something like this: shapeName = GraphicsWindow.addEllipse(5,5) You can pass in a more than one thing to an operation, but operations in Small Basic will only return one thing.
21
Using the Small Basic Classes Many programs use some of the Math functions, as well as some of the Clock functions. Clock.getMonth() Clock.getDay() Clock.getCurrentTimeMillis() What is the last one good for? We can use it as sort of a stopwatch, to figure out how long something in our program is taking.
23
Experiment! Import SKT673 and have some fun with it! Use some of the classes you see in the documentation!
24
Our Programs Need to Make Decisions We need our programs to be able to make decisions. Let’s look at the following code: If (Clock.Day = 1) And (Clock.Month = 1) Then TextWindow.WriteLine("Happy New Year") EndIf What do you think this program does?
25
Next Time... Next time, we’re going to continue with the branching functionality that is available. Learn how to type! A good place to start is at http://www.typingweb.com. It has ads, but you can skip creating an account (just close the window) and jump to the lessons. http://www.typingweb.com
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.