Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.

Similar presentations


Presentation on theme: "CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre."— Presentation transcript:

1 CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre

2 RECITATIONS (LABS) Section 1 Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 2

3 Labs Begin This Week Go to Bell hall [next to Student Union] Room 340. – There is key card access that your card won’t open, so you will need to wait for the TA sometimes to show up to let you in. – If you queue in the hall, please be respectful of the offices and classrooms around you. Please go to your lab. – It is mandatory. – Attendance counts towards your grade. – There is an end of class assessement/quiz. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 3

4 What do I do in lab? You will be doing the chapters from the Greenfoot book, step by step. Do each exercise. – You do not need to record your answers. – The assessment/quiz at the end of the class may require you to answer some questions about those exercises. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4

5 When I am done, what do I do? After you go through the chapters that you need to cover, you will: – Work on your project. – Take the assessment/quiz at the end of class. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

6 Can’t I take the quiz and leave? No. Use the two hours to experiment and work on your project. – If you at some point become done with your project, then work on it more. – Think of your project as an art piece, Leonardo da Vinci said that “art is never finished, only abandoned.” – When your project is due, that is when you are done! Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6

7 For the First Week in Recitaiton For the week of September 7 th – Please read chapter 1 and chapter 1 exercises. – Please read chapter 2 and chapter 2 exercises. – Please finish by taking the assessment/quiz. – At that point, for this week only, you can leave early! The first project will be assigned next week. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 7

8 GREENFOOT – INTERFACE Section 2 Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 8

9 Demonstration You will become more familiar with the interface when you go hands-on with the book in the lab. I will demo the interface here to show you around. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 9

10 GREENFOOT – CHAPTER 2 Section 3 Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

11 Chapter 2 In this chapter you will learn: – How to start writing code. – How to find out what methods you can use. – What an “if”-statement is! (Probably the most important control statement you will learn.) Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

12 What is “inheritance”? It is the “is-a” relationship between classes For example: – “A dog is-a mammal” – “A chiuaua is-a dog” This means that a dog “inherits” all the features that a mammal may have. “Sub-classes” (see last weeks notes) inherit their properties and methods from their “Super-classes” Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 12

13 Crab and Animal classes Notice the arrow direction in the Actor classes tree. – A crab is-a animal. – An animal is-an actor. – Thus a crab is-a actor too! Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 13

14 Classes can inherit methods The animal class has a method called “act”, so that means that the crab class will also have that method. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 14

15 Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 15

16 What do the methods do? There are many methods in the animal class: – “act” method, does nothing. – “move” method, moves the actor in a forward direction. – “turn” method, rotates the actor a number of degrees specified in the parameter. – “atWorldEdge” method, returns a boolean value indicating if the actor is at the edge of the world. What we will do is make the “act” method do something, like call the “move” method. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 16

17 Writing code To begin writing code, let Greenfoot do the framework for you. – Double-click on the class to get the editor. – Go to the already formed “act” signature. – We can add “move();” within the brackets { } to make it move. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 17

18 Note: brackets and semicolons You need to adhere to a specific “syntax”. When you write English, we need to use “,” and “.” appropriately otherwise the reader will misread what you have written. It is the same thing with Java, you need to use the “{“, “}” and “;” correctly or it will not understand you. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 18

19 Semicolons A semicolon “;” indicates an end of a command. It is similar to a “.” at the end of an English sentence. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 19

20 Brackets and code blocks The instructions between a set of brackets is called a “code block” or the “body” of a method. You must match each “{“ with a “}” Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 20

21 Syntax errors: Ooops, I messed up?! This will happen a lot. Greenfoot with alert you to a mistake. You can see if you have any syntax mistakes by compiling or running your code. Note: Sometimes you will have two or more mistakes, causing your code to compile/run, but not work properly. This is not a syntax error, this is a code error. Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 21

22 To be continued on Friday Wednesday, Sept. 7th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 22


Download ppt "CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre."

Similar presentations


Ads by Google