Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 113 Introduction to Computer Programming Lecture slides for Week 7 Monday, October 10 th, 2011 Instructor: Scott Settembre.

Similar presentations


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

1 CSE 113 Introduction to Computer Programming Lecture slides for Week 7 Monday, October 10 th, 2011 Instructor: Scott Settembre

2 COURSE ADMINISTRATION Section 1 Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 2

3 For Project Assistance 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 10/10/2011: (Also come to additional labs if you need help) Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 3 NameEmail addressOffice hours Bich (pronounced “Bic”) Vubtvu@buffalo.eduM (11-11:50am) Bell 329 F (12-12:50pm) Bell 329 Troy Kosstroykoss@buffalo.eduTues (3-5pm) Bell 329 Scott Settembress424@buffalo.eduM (10-11am) Bell 232 F (10-11am) Bell 340 Also at all times by email AND video conference by appointment.

4 You are behind the class if… If you have not: – completed chapter 1-5, then you are behind the rest of the class. – made significant progress on your project, then you are behind the rest of the class. – experienced how to construct an “if” statement or a “while” statement, then you are going to have problems on the test. Please do the following: – Complete chapter 1-5 in Bell 101. – Finish your project by Friday. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 4

5 Lecture and Lab this Week Lectures will go over the following: – Chapter 6 concepts Abstract classes Overloading method names The keyword “this” – referring to the current object Shared variables – use of the keyword “static” Constants – use of the keyword “final” Lab will have you do the following: – Finish completely chapters 1-5 if you haven’t – Finish your Project 1 – Begin chapter 6 up to and including 6.4 – Lab Quiz on chapters 1-5 (not 6) Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 5

6 MIDTERM / FINAL EXAM / PROJECT Section 2 Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 6

7 Midterm exam (15%) The midterm exam will be held in lecture on October 21 st. It will cover chapters 1-6.4, including the exercises in the chapter that you do in lab. It will be a series of true/false, multiple choice, and code examination (running the code in your head), similar to the quizzes that you will have taken. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 7

8 Final Exam (25%) The final exam will be during class during the last week of class. It may span two days (I may give half on one day and half the next day). It will consist of questions like the quizzes, as well as some code reading and understanding. More on this in November. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 8

9 Project 1 Due date: October 14 th, 2011 at or before 11:59:59 PM Get’r done! Submit appropriately, using the steps outlined in the Course Documents – Submission Steps.pdf file. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 9

10 CHAPTER 6 Section 3 Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 10

11 The “double” type A “double” type is declared like so: double pi;// pi is declared as a floating point number pi = 3.14159;// pi now equals 3.14159 It can be a value that ranges between a negative and positive range of numbers. – Typically, it is any 7 place decimal number between -10 38 and +10 38. You can set its initial value when you declare it: double pi = 3.14159;// pi declared & set to 3.14159 Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 11

12 What is an “abstract” class? A class that you cannot make an instance (i.e. an object) from. Why? – Well, the code acts more like an “outline” or a summary, but has no real substance. – It is meant to get you started with your sub-class, providing you with some code, some method names, and some instance variables. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 12

13 The abstract keyword You can always tell if a class is an abstract class, by looking at the class signature: Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 13 import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A variation of an actor that maintains precise location (using doubles for the co-ordinates * instead of ints). It also maintains a current movement in form of a movement vector. * * @author Poul Henriksen * @author Michael Kolling */ public abstract class SmoothMover extends Actor { private Vector movement; private double exactX; private double exactY; public SmoothMover() … This abstract keyword indicates that this class can only be a super-class of other classes, it cannot be instanced into an object.

14 Abstract class example Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 14 Actor Vehicle Car Boat Bicycle Abstract class. Code from this class can only be used from a subclass.

15 Why can’t you make an instance out of “Vehicle” then? Well, if you look at the “vehicle” code, you will probably not find anything specific about a specific type of vehicle. Instead, you will find generic methods and instance variables like “move”, “wheels”, or “getPassengerList”. Creating an object out of that, may not make any sense because you can’t ask the object to “do” anything. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 15

16 Let’s look at another class The “Car” class has a constructor: Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 16 public class Car extends Vehicle { private int wheels; private int color; public Car() { wheels = 4;// Default to 4 wheels color = 0;// Default to color ‘0’ – which == black } This is called the “default constructor” of a class. It has no parameters in the parameter list.

17 What is “overloading”? When you write two or more methods that use the SAME name, you are overloading a method. When you “overload” a method, – You use the same name as an already defined method. – You must change the parameter list so the compiler knows which method definition to use. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 17

18 Why should we overload? It is a useful technique, so that you can use the same code. It allows you to “ask” or “command” the object the same thing, in different ways. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 18

19 Overloading example Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 19 public class Car extends Vehicle { private int wheels; private int color; public Car() { wheels = 4;// Default to 4 wheels color = 0;// Default to color ‘0’ } public Car ( int initialColor ) { wheels = 4; color = initialColor; } Notice that the method has the same name, but the parameter list is different. This means, you can initialize the car two different ways: 1.either by giving no information to the constructor, or 2.by giving color information to the constructor.

20 Let’s take a different look at this example Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 20 public class Car extends Vehicle { private int wheels; private int color; public Car() { wheels = 4;// Default to 4 wheels color = 0;// Default to color ‘0’ } public Car ( int color ) { wheels = 4; color = color; } I have changed the name from “initialColor” to “color”. Now how will the compiler know which color I am referring to? The “color” from the paramter list or the private instance “color”?

21 The this keyword There is a keyword called this, which allows the code to refer to the current object running. Remember, if you have more than one object of a specific class, each object runs the SAME code, but has different instance variables. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 21

22 Bunch of cars Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 22 Car 1 wheels = 4 color = 0 Car 2 wheels = 4 color = 255 Car 3 wheels = 4 color = 59 All these private instance variables values exist in memory at different locations, but the constructor code exists in only one location. public Car () {…} Public Car (int color) {…} So if we are in this code here, how do we know where to put the “color” value?

23 Using this keyword Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 23 public class Car extends Vehicle { private int wheels; private int color; public Car() { wheels = 4;// Default to 4 wheels color = 0;// Default to color ‘0’ } public Car ( int color ) { wheels = 4; this.color = color; // Assign color to the instance variable. } Now how will the compiler know which color I am referring to? “this.color” refers to the current object’s instance variable, whereas the “color” is the “color” value from the parameter list of the method.

24 Another use of this this can also be used to call the constructor of a class. – Yes, I know I told you that you cannot call the constructor of a class, except once at the creation of the object, but this is an exception. – You must call it from within an overloaded constructor, thus it really is a constructor calling a constructor. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 24

25 Using this keyword to call a constructor Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 25 public class Car extends Vehicle { private int wheels; private int color; public Car() { this (0);// call the Car overloaded constructor with default value for color } public Car ( int color ) { wheels = 4; // Default to 4 wheels this.color = color; // Assign color to the instance variable. } The default constructor will now call the overloaded constructor with a default value for color.

26 PREVIEW FOR PROJECT 2 Section 4 Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 26

27 Project 2 - Discussion I’ll release the description of project 2 on Monday and I will discuss it in class. Project 2 will further explore your programming skills, but more importantly, it will show you the power of Object Oriented Programming (OOP) You don’t need a CS degree to work magic! Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 27

28 Micro-mouse Competitions Academic based competitions to encourage autonomous robot development. Here are some links: – Very fast final solution run: http://www.youtube.com/watch?v=eVh644Asb9o&fe ature=related http://www.youtube.com/watch?v=eVh644Asb9o&fe ature=related – Shows learning phase & @4min the final solution run: http://www.youtube.com/watch?v=ZszTOpILeP0&feat ure=related http://www.youtube.com/watch?v=ZszTOpILeP0&feat ure=related Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 28

29 DARPA Grand Challenge The DARPA Grand Challenge is a government prize-backed challenge to encourage development of autonomous vehicles. Autonomous vehicles are vehicles that can drive on their own, WITHOUT human supervision. This is different than Remotely Operated Vehicles (ROV), in that ROV’s have humans remotely telling the aircraft what to do. Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 29

30 DARPA Grand Challenge Videos http://www.youtube.com/watch?v=-xibwwNVLgg&feature=related – @13:38 challenge rules explained http://www.youtube.com/watch?v=lULl63ERek0 – @ :45 is hardware review, you can skip. – @1:20 is a good background explanation of what the challenge had. Good vehicle video. http://www.youtube.com/watch?v=SQFEmR50HAk – No voiceover, pure video caps. http://www.youtube.com/watch?v=0eMJaHQGhtQ – Team Buffalo!!! Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 30

31 What will you need to do? Stay tuned and find out on Monday! Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 31

32 Robotic Car – Think about it Monday, Oct. 10th, 2011 University at Buffalo: CSE 113 Instructor: Scott Settembre 32 Actor Robot RobotCar Sensor BumpSensor


Download ppt "CSE 113 Introduction to Computer Programming Lecture slides for Week 7 Monday, October 10 th, 2011 Instructor: Scott Settembre."

Similar presentations


Ads by Google