Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre.

Similar presentations


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

1 CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre

2 ADMINISTRATION NOTES Section 1 Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 2

3 Greenfoot Details The Greenfoot resource page that can be found at: http://www.greenfoot.org/book/ I usually put the information we need and copy it to UBLearns, but you may find the link above useful, as well as the following link for additional information, videos, and tips: http://www.greenfoot.org/ Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 3

4 Lab Attendance Lab attendance is definitely mandatory. If you cannot go to your assigned lab (or miss it), then you should ask your TA if you can go instead to another lab time. Lab times are: Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4 Lab DaySection #TimeTA in charge WedB112-1:50pmBich Vu WedB42-3:50pmTroy Koss ThursB29-10:50amTroy Koss FridayB310-11:50amBich Vu

5 Contact You can email any one of the TA’s for your questions and if they cannot help you, please do email me. Remember to include “CSE113:” in the subject line. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

6 Teacher Assistants and Office hours You can find the up-to-date hours and locations in the “Contact” section of UBLearns. Here are the names, emails, and office hours as of 9/12/2011: Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6 NameEmail addressOffice hours (Bell 329) Bich (pronounced “Bic”) Vubtvu@buffalo.eduMonday (11-11:50pm) Friday (12-12:50pm) Troy Kosstroykoss@buffalo.eduTuesday (3-5pm) Scott Settembress424@buffalo.eduTDB after poll class

7 UB Helpful Information UB Free Software http://ubit.buffalo.edu/software/ Using your own computer at UB http://ubit.buffalo.edu/newstudent/ Help from UB IT https://wiki.cse.buffalo.edu/services/ FREE Microsoft Software – ALL OF IT! – MSDN-AA https://wiki.cse.buffalo.edu/services/content/microsoft- developer-network-academic-alliance-msdn-aa Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 7

8 VERY IMPORTANT! Go to Bell 101 and log in by Monday, September 12 th, 2011. – Your username/password is the same as your UB Email username/password. If you cannot log in, the make sure you get your account enabled. – Either talk to the attendant on duty in Bell 101, OR – Go to: http://www.sens.buffalo.edu/accounts/http://www.sens.buffalo.edu/accounts/ If you go to lab and cannot log in, everyone will point and laugh at you!!! Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 8

9 You are behind the class if… If you have not completed chapter 1 and started chapter 2, then you are behind the rest of the class. Please do the following: – Attempt setting up and doing chapter 1 and 2 in Bell 101. – If you have too much trouble getting started, then: Go to a TA office hour, OR Email a TA, OR Go to an additional lab section before you go to your lab. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 9

10 GETTING STARTED NOTES Section 2 Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

11 Lab Tips from Week 2 If you didn’t have the book at this time, you had the option to use the “tutorial” at the Greenfoot website: http://www.greenfoot.org/doc/tutorial/tutorial.html In addition, free chapters 2 and 3 could also be downloaded from: http://www.greenfoot.org/book/toc.html Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

12 Greenfoot Scenarios For this course, in order to follow the book, you need to additionally download the book scenarios. I have posted them on UBLearns (guaranteed virus free), or you can download them directly from the book website: http://www.greenfoot.org/book/ (Click the second link in the section marked “For students”) You should create a directory called “greenfoot” and then place the extracted “book-scenarios” directory into that directory. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 12

13 For those that used the Tutorial… Please quickly do/look through chapter 1 when you get the book to make sure that you understand all the concepts. The tutorial also has some “vague” instructions, including where you should place the code and a change that is fixed if you change all the “.gif” references to “.png”. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 13

14 CHAPTER 3 Section 3 Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 14

15 What is a “package”? A package is a bunch of code. – It may be one file or many files. – It may call methods or use objects from any of those files. – Usually, a package contains related objects and there is some dependency. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 15

16 Can “objects” be created using packaged code? In this course, you will find the answer to this to be “Yes.” However, you do not always need to create an object to use the code in a package. These are called “static” methods. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 16

17 I’m confused, “static” methods? We have been shown that objects can have methods. We have seen how to call an object method. In the case of “static” methods, these are not part of an instantiated object (a created object), instead they are part of the class. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 17

18 “static” method demo See that when we call the “getRandom” method, we need to refer to the package name. This “reference” to the method is called “dot notation”. The package name is proceeded by a “.” period and then by the name of the method you wish to call. – For example, “Greenfoot.getRandomNumber(100);” Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 18

19 What is a “subclass”? A subclass is a more specific instance of its superclass. – A “dog” is more specific than “animal”. – A “dog” object would then have functionality (methods or properties) that are not in “animal”. – For example, a method called “wagTail” could be in the “dog” class, but not the “animal” class, since not all animals have tails. We can create a subclass quite easily in Greenfoot. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 19

20 New subclass demonstration You create a new subclass by right-clicking on the class and then selecting “new subclass”. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 20

21 Adding new code to a class To add new code to a class, you will want to put the method signature inside the “code block” of the class. The “code block” is the outer set of curly braces “{“ and “}” The new method must be inside that code block so that the computer knows that it describes a method that belongs to that class. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 21

22 Adding a new method demo Go to the code of the new class and show where to put any new methods that will be created. Notice how the new method then appears in the dropdown menu of any new object you create of the new class. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 22

23 Number comparisons In this chapter, you will have the need to compare numbers (or the return values of methods) to other numbers. Java has the following comparison operators: Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 23 OperatorMeaningExample ==Equal to5 == 5 !=Not equal to5 != 2 Greater than6 > 4 <=Less than or equal to5 <= 5 >=Greater than or equal to6 >= 6

24 Comparisons can be used in Boolean Expressions The “if” statement contains a test for a Boolean expression. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 24 public void act() { if ( atWorldEdge() ) { turn(17); } if ( Greenfoot.getRandomNumber(100) < 10 ) { turn(5); } move(); } Notice that the there is a comparison here that compares the return value from the static method “getRandomNumber” to the value 10.

25 Getting input from users This is one of the more important things to know how to do. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 25 public void checkKeypress() { if (Greenfoot.isKeyDown(“left”)) { turn(-4); } if (Greenfoot.isKeyDown(“right”)) { turn(4); } Notice that “isKeyDown” is a static method of the package “Greenfoot”. You do not have an object called “Greenfoot”.

26 Lab for this week You will experiment and learn how to use these key concepts. – Making a subclass. – Writing a new method. – Calling “static” methods of a package. – Getting keyboard input. Get to know how to do this, since you will need to understand how to do these things to get a good grade on project 1. Monday, Sept. 12th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 26


Download ppt "CSE 113 Introduction to Computer Programming Lecture slides for Week 3 Monday, September 12 th, 2011 Instructor: Scott Settembre."

Similar presentations


Ads by Google