1 / 22

CSE 113 Introduction to Computer Programming

CSE 113 Introduction to Computer Programming. Lecture slides for Week 2. Wednesday, September 7 th , 2011 Instructor: Scott Settembre. Section 1. Recitations (Labs). Labs Begin This Week. Go to Bell hall [next to Student Union] Room 340.

oihane
Download Presentation

CSE 113 Introduction to Computer Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Section 1 Recitations (Labs) University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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!  University at Buffalo: CSE 113 Instructor: Scott Settembre

  7. 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

  8. Section 2 Greenfoot – Interface University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  10. Section 3 Greenfoot – Chapter 2 University at Buffalo: CSE 113 Instructor: Scott Settembre

  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.) University at Buffalo: CSE 113 Instructor: Scott Settembre

  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” University at Buffalo: CSE 113 Instructor: Scott Settembre

  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! University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  15. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  19. 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

  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 “}” University at Buffalo: CSE 113 Instructor: Scott Settembre

  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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  22. To be continued on Friday University at Buffalo: CSE 113 Instructor: Scott Settembre

More Related