BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Lecture 2 Calling and Defining Methods in Java. Introduction ●Calling and defining methods ●Declaring and defining a class ●Instances of a class ●The.
Lecture 1: Overview CMSC 201 Computer Science 1 (Prof. Chang version)
Section 1.3 Prime numbers and fractions
Lecture 6a Instructor: Craig Duckett. Upcoming Assignments & Mid-Term Assignment 1 Revision Assignment 1 Revision is due NEXT Wednesday, July 29 th, by.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
BIT 115: Introduction To Programming1 Sit in front of a computer Log in –Username: 230class –password: –domain: student Bring up the course web.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
Math 010 online work that is due today at the start of class: Gateway Homework #3 (turn in worksheet now, while I take roll) Section 1.2/1.8 Online Homework.
Lecture 6 Instructor: Craig Duckett. Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment.
BIT 115: Introduction To Programming Instructor: Mike Panitz
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Mtivity Client Support System Quick start guide. Mtivity Client Support System We are very pleased to announce the launch of a new Client Support System.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
1 CS161 Introduction to Computer Science Topic #9.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
CreatingSubclasses1 Barb Ericson Georgia Institute of Technology Dec 2009.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
BIT 143: Programming – Data Structures It is assumed that you will also be present for the slideshow for the first day of class. Between that slideshow.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Wednesday, January 20 th one week from today I will.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
For Friday Finish reading chapter 2 Complete WebCT quiz.
Georgia Institute of Technology More on Creating Classes part 3 Barb Ericson Georgia Institute of Technology Nov 2005.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
OOP Basics Classes & Methods (c) IDMS/SQL News
CSS 290: Video Games and Computer Programming Instructor: Mike Panitz Tuesdays and Thursdays, 1:15pm-3:20pm UW
Classic Connections: Innovative Methods for Making Education Work.
1 1.Log in to the computer in front of you –Temp account: 210class / 2.Update your in Cascadia's system –If I need to you I'll use.
Introduction to Exceptions in Java CS201, SW Development Methods.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Lecture 11 Instructor: Craig Duckett Instance Variables.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Problem of the Day  Why are manhole covers round?
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Monday, October 10 th I will double dog try to have.
BIT 115: Introduction To Programming L ECTURE 3 Instructor: Craig Duckett
Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
External Scope CECS 277 Mimi Opkins.
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
BIT115: Introduction to Programming
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
We’ll be spending minutes talking about Quiz 1 that you’ll be taking at the next class session before you take the Gateway Quiz today.
CS2102: Lecture on Abstract Classes and Inheritance
slides created by Ethan Apter
CISC101 Reminders Assn 3 due tomorrow, 7pm.
slides created by Ethan Apter
Log in to the computer in front of you
Blackboard Tutorial (Student)
BIT 115: Introduction To Programming
Java Programming Language
More on Creating Classes part 3
CISC101 Reminders Assignment 3 due today.
Presentation transcript:

BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”

Names Put your name on your computer using a card/sticky note Don’t sit alone Log into Canvas BIT 115: Introduction To Programming2

Adding and Keeping Up There are a few spots left so I will sign add forms for those on wait list But everyone must be caught-up with all current assignments by Thursday! BIT 115: Introduction To Programming3

4 Today Announcements & Q + A on prior topics (<= 5 minutes) Quiz #3 (5 minutes) Making New Types of Robots Creating new commands/methods (like a ‘turnRight’ command)

Lecture 3 Announcements By now everyone should be up and running with Java, jGRASP/Eclipse, and the Becker Robots on their home or personal computers. Any Problems? Has everyone had a chance to work with the Java programs and the Becker Robots? Reading Assignment for Today Appendix F.1 – Extending a Class Chapter 2.1, 2.2 – Extending Robot Class Chapter 2.4 – Coding Style BIT 115: Introduction To Programming 5

Staying Organized Keep up by checking daily and reviewing Canvas Calendar and Tentative Course Schedule at the bottom of Syllabus Let’s look at it now BIT 115: Introduction To Programming 6

Asking For Help Start Homeworks As Soon As Possible! Unless it’s about your grades, or something specific to a homework assignment, post to the relevant Canvas Discussions first BE SPECIFIC What were you trying to do List what you did up to that point State clearly what you expected to happen State clearly what actually happened You must make at least 2 Canvas Discussion posts before the midterm (& at least 2 more afterwards) Read the associated Canvas Discussion Contributions assignments and Rubric BIT 115: Introduction To Programming 7

Asking For Help: Open Lab Tuesdays and Thursdays: 11am – 1pm: Brian, in room CC1-211 except for the following days & times: The room is in use for all of Tuesday, December 15 th If Continuing Education happens to need the room they may pre-empt us, possibly with short notice. 1:15 to 3:15: Elijah, in room CC1-221 except for the following days & times: We will need to be out of the room by 3pm on Thursday, October 15th, October 19th, & December 17th, since someone else needs the room then There's a lab monitor who can help, if you ask nicely BIT 115: Introduction To Programming 8

9 Homework A1 is due next class, at the start of class Hand-in will be done via Canvas; upload.doc files to the Canvas assignment, submit.java files to the relevant Java Code Critic Module assignments Let look at those now Try submitting something tonight If you run into trouble, get help! Contact your professor immediately! How? See the Canvas Announcement titled “How to Report Problems” A2 has been posted online Skim through it, and work on parts as we cover them in class.

BIT 115: Introduction To Programming 10 Quiz03 under Quizzes in Canvas Access Code:think 5 minute limit The First Quiz And Now…. The First Quiz!

BIT 115: Introduction To Programming 11 Make Your Own Robot Commands So far we’ve done simple stuff We’re (eventually) going to be doing more complicated stuff We need ways to make the program seem more simple, so we don’t get (as) lost. Today: Creating a new type of robot! By extending a class Predicting What A Program Will Do BEFORE you Run It

Appendix F.1, Chapter 2.1, 2.2 Extending a Class BIT 115: Introduction To Programming 12 Extension (B extends A) Extending the Robot Class Superclass and Subclass Constructor Adding a Service turnAround(); turnRight(); The This Keyword (Implicit Parameter) Putting It All Together

Calling a Constructor BIT 115: Introduction To Programming 13 Here, when we create a new instance (an object) of the Robot class, a ‘hidden’ default constructor works in the background to make sure that Kelsey inherits all the attributes and methods available to Robots, including its placement on a particular Street and Avenue and Direction in a particular City, and that it can use all of the actions (methods) available to the Robot class (including move(), pickThing(), turnLeft(), putThing(), frontIsClear(), etc.)

Calling a Constructor BIT 115: Introduction To Programming 14 Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object, as in: The purpose of a method, by contrast is much more general. The purpose of a method is to execute Java code, to allow the object to do something.

BIT 115: Introduction To Programming15

BIT 115: Introduction To Programming16 N ow … what if these is an action that you might want Kelsey to do that isn’t found in the Robot class? For instance, instead of invoking the the turnLeft() method three times, you could just call up a turnRight() ? The problem is, the Robot class does not have a turnRight() command (method). The Robot class has been finalized. You cannot add to it. The good news is, you can create a new method like turnRight() that will do what you want the robot to do! But in order to make this happen, you need to extend the Robot class …

Extending a Class: Where Class B extends Class A BIT 115: Introduction To Programming 17 In Plain Ol’ English: Where Class B “inherits” the attributes and actions of Class A … then adds new functionality to them. public class Example extends Object When we’re not interested in extending a class because we’re happy with the methods that come with the java.lang.Object class just the way they are, then we declare our class the ‘normal’ default way: However, if we want to add new functionality (methods) to the Robot class (like turnRight) then we need to extend the Robot class (which is itself an extension of Object) public class MrRoboto extends Robot Object is the top class of all class hierarchies. When a new instance of anything is made in Java, then it inherits all the attributes and actions of the java.lang.Object class. You can’t get a new object without the Object class. Class Hierarchy Object

Extending a Class: Where ClassB extends ClassA BIT 115: Introduction To Programming 18 Instance vs. Extension? An instance is a new object from a class, but extension extends a new class from a class through inheritance, allowing for an improved class that might offer additional attributes and services (methods) not available in the original class …

Extending the Robot Class BIT 115: Introduction To Programming 19 public class MrRoboto extends Robot Robot MrRoboto MrRoboto “inherits” all of the Robot attributes and services and then can have additional attributes and services of its own (i.e., those not shared by Robot). Extends/Inherits from

Superclass and Subclass BIT 115: Introduction To Programming 20 Robot MrRoboto Superclass/Parent Subclass/Child

Writing a Constructor BIT 115: Introduction To Programming 21 import becker.robots.*; public class MrRoboto extends Robot { public MrRoboto(City theCity, int street, int avenue, Direction aDirection) { super(theCity, street, avenue, aDirection); } //New service or services go here }

Writing a Constructor BIT 115: Introduction To Programming 22 import becker.robots.*; public class MrRoboto extends Robot { // This declares the parameters used by Robot “inside” of MrRoboto public MrRoboto(City theCity, int street, int avenue, Direction aDirection) // This passes on information received by the parameters used by Robot ‘inside” of MrRoboto { super(theCity, street, avenue, aDirection); //Instead of Robot here, Java uses the keyword super } //New service or services go here } Constructors fulfill a special roll. They are responsible for ensuring an object is set up properly when it is created, and that it can be immediately used once it is created. This construction process is known as initialization. Two other details about constructors: they must have the same name as the class and they do not have a return type, not even a void. NOTE: We will talk briefly about return types in just a few minutes, and go over them in greater detail in an upcoming lecture.

Constructor BIT 115: Introduction To Programming23 public class MrRoboto extends Robot { public MrRoboto(City theCity, int street, int avenue, Direction aDirection) { super(theCity, street, avenue, aDirection); } } Robot MrRoboto

Constructor BIT 115: Introduction To Programming24 public class MrRoboto extends Robot { public MrRoboto(City theCity, int street, int avenue, Direction aDirection) { super(theCity, street, avenue, aDirection); } } Robot super MrRoboto

Constructor BIT 115: Introduction To Programming25 public class MrRoboto extends Robot { public MrRoboto(City theCity, int street, int avenue, Direction aDirection) { super(theCity, street, avenue, aDirection); } } super MrRoboto  imagine a conduit …

Constructor BIT 115: Introduction To Programming26 public class MrRoboto extends Robot { public MrRoboto(City theCity, int street, int avenue, Direction aDirection) { super(theCity, street, avenue, aDirection); } } super MrRoboto bothell, 3, 2, Direction.SOUTH Since MrRoboto is inheriting the Robot parameters, the Robot still needs those parameters in order for MrRoboto to inherit them. This is why it appears as if there are two sets of parameters: one set to pass through MrRoboto, a second set for Robot to receive them, where Robot sends them back to MrRoboto by extension.

Adding New Methods/Services 27 public void turnAround() { this.turnLeft(); this.turnLeft(); } public void move3() { this.move(); this.move(); this.move(); }. public void turnRight() { this.turnAround(); this.turnLeft(); }

The this keyword 28 The new Java feature in the new services we created is the use of the this keyword. The keyword this is useful when you need to refer to an instance of the class from its method, but without having to refer to it by a specific name. Why? Because when you create the new method, you don’t know the name of the particular robot that is going to use it, so ‘this’ is a kind of placeholder name. The this keyword helps us to avoid name conflicts, and also creates a shortcut to having to invent a unique name for each field in the different methods. public void turnAround() { this.turnLeft(); this.turnLeft(); }

Putting It All Together 29 Two Ways of Doing the Same Thing, however: THE CLASS THAT CONTAINS MAIN HAS TO BE THE SAME NAME AS THE FILE Version 1: One Class MrRoboto.java Version 2: Two Classes MrRobotoMain.java

Putting It All Together 30 MrRoboto2.java MrRobotoTest2.java MrRoboto.java All on One FileOn Two Separate Files

Canvas Discussions For most questions, try there, first Do NOT post questions about your grades Do NOT post questions about doing Assignment 1 You need to do this on your own DO post questions about stuff like “How do I install Java/jGRASP?” “Where is homework assignment 1?” “I’m having trouble handing in A1”, “I have a question about something we did in class”, etc. BIT 115: Introduction To Programming 31

ICE03 In our course’s Canvas Assignments Upload.doc files to the Canvas ICE03 assignment Paste in.java file to Java Code Critic Module (ICE03 assignment) If you finish early, help your classmates then work on A1 & then A2 If you finish late, make sure you turn all pieces in before our next class BIT 115: Introduction To Programming32