1 / 32

CSE 113 Introduction to Computer Programming

CSE 113 Introduction to Computer Programming. Lecture slides for Week 7. Monday, October 10 th , 2011 Instructor: Scott Settembre. Section 1. Course Administration. For Project Assistance. You can find the up-to-date hours and locations in the “Contact” section of UBLearns .

ariane
Télécharger la présentation

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 7 Monday, October 10th, 2011 Instructor: Scott Settembre

  2. Section 1 Course Administration University at Buffalo: CSE 113 Instructor: Scott Settembre

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

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

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

  6. Section 2 Midterm / Final exam / Project University at Buffalo: CSE 113 Instructor: Scott Settembre

  7. Midterm exam (15%) • The midterm exam will be held in lecture on October 21st. • 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  9. Project 1 • Due date: October 14th, 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  10. Section 3 Chapter 6 University at Buffalo: CSE 113 Instructor: Scott Settembre

  11. The “double” type • A “double” type is declared like so: doublepi; // 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 -1038 and +1038. • You can set its initial value when you declare it: doublepi = 3.14159; // pi declared & set to 3.14159 University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  13. The abstract keyword • You can always tell if a class is an abstract class, by looking at the class signature: 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 PoulHenriksen * @author Michael Kolling */ public abstract class SmoothMoverextends Actor { private Vector movement; private double exactX; private double exactY; publicSmoothMover() … This abstract keyword indicates that this class can only be a super-class of other classes, it cannot be instanced into an object. University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  15. Why can’t you make an instanceout 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  16. Let’s look at another class • The “Car” class has a constructor: public class Car extends Vehicle { private intwheels; private intcolor; 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

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

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

  19. Overloading example public class Car extends Vehicle { private intwheels; private intcolor; public Car() { wheels = 4; // Default to 4 wheels color = 0; // Default to color ‘0’ } public Car ( intinitialColor ) { 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: either by giving no information to the constructor, or by giving color information to the constructor. University at Buffalo: CSE 113 Instructor: Scott Settembre

  20. Let’s take a different lookat this example public class Car extends Vehicle { private intwheels; private intcolor; 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”? University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  22. Bunch of cars 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? University at Buffalo: CSE 113 Instructor: Scott Settembre

  23. Using this keyword public class Car extends Vehicle { private intwheels; private intcolor; 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  25. Using this keywordto call a constructor public class Car extends Vehicle { private intwheels; private intcolor; 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. University at Buffalo: CSE 113 Instructor: Scott Settembre

  26. Section 4 Preview for project 2 University at Buffalo: CSE 113 Instructor: Scott Settembre

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

  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&feature=related • Shows learning phase & @4min the final solution run: http://www.youtube.com/watch?v=ZszTOpILeP0&feature=related University at Buffalo: CSE 113 Instructor: Scott Settembre

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

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

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

  32. Robotic Car – Think about it Actor Robot RobotCar Sensor BumpSensor University at Buffalo: CSE 113 Instructor: Scott Settembre

More Related