220 likes | 349 Vues
In this Week 2 lecture for CSE 113 at the University at Buffalo, Instructor Scott Settembre introduces lab sessions, which start this week. Attend mandatory labs in Bell Hall Room 340. Students will work through exercises from the Greenfoot book, covering key programming concepts, including control statements like "if" and inheritance in classes. This week, focus on Chapters 1 and 2, and remember that participation counts toward your grade. Embrace the project as a creative process.
E N D
CSE 113Introduction toComputer Programming Lecture slides for Week 2 Wednesday, September 7th, 2011 Instructor: Scott Settembre
Section 1 Recitations (Labs) University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
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! University at Buffalo: CSE 113 Instructor: Scott Settembre
For the First Week in Recitaiton • For the week of September 7th • 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. University at Buffalo: CSE 113 Instructor: Scott Settembre
Section 2 Greenfoot – Interface University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
Section 3 Greenfoot – Chapter 2 University at Buffalo: CSE 113 Instructor: Scott Settembre
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.) University at Buffalo: CSE 113 Instructor: Scott Settembre
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” University at Buffalo: CSE 113 Instructor: Scott Settembre
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! University at Buffalo: CSE 113 Instructor: Scott Settembre
Classes can inherit methods • The animal class has a method called “act”, so that means that the crab class will also have that method. University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
Semicolons • A semicolon “;” indicates an end of a command. • It is similar to a “.” at the end of an English sentence. University at Buffalo: CSE 113 Instructor: Scott Settembre
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 “}” University at Buffalo: CSE 113 Instructor: Scott Settembre
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. University at Buffalo: CSE 113 Instructor: Scott Settembre
To be continued on Friday University at Buffalo: CSE 113 Instructor: Scott Settembre