BIT 115: Introduction To Programming

Slides:



Advertisements
Similar presentations
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
Advertisements

CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Call-by-Value vs. Call-by-Reference Call-by-value parameters are used for passing information from the calling function to the called function (input parameters).
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
BIT 115: Introduction To Programming LECTURE 3 Instructor: Craig Duckett
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Constructors & Garbage Collection Ch. 9 – Head First Java.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Chapter 9 Life & Death of an Object Stacks & Heaps; Constructors Garbage Collector (gc)
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Lecture 11 Instructor: Craig Duckett. Announcements Assignment 1 Revision DUE TONIGHT February 10 th In StudentTracker by midnight If you have not yet.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
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)
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Lecture 11 Instructor: Craig Duckett Instance Variables.
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”
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”
N ESTED C LASSES -1. T YPES OF N ESTED C LASSES & I NTERFACES top-level nested classes interfaces inner classes member local named anonymous.
Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
BIT 115: Introduction To Programming L ECTURE 3 Instructor: Craig Duckett
BIT115: Introduction to Programming
Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
BIT 115: Introduction To Programming
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
Classes and Objects Introduced
BIT 115: Introduction To Programming
BIT 115: Introduction To Programming
OOP: Encapsulation &Abstraction
Lecture 14 Throwing Custom Exceptions
Static data members Constructors and Destructors
Examples of Classes & Objects
The Lifetime of a Variable
BIT 115: Introduction To Programming
Some Eclipse shortcuts
BIT 115: Introduction To Programming
BIT115: Introduction to Programming
Lecture 10: More on Methods and Scope
BIT 115: Introduction To Programming
Chapter 4: Writing Classes
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
BIT115: Introduction to Programming
Arrays & Functions Lesson xx
BIT115: Introduction to Programming
Lesson 2: Building Blocks of Programming
Class Structure 16-Nov-18.
Lecture 11 C Parameters Richard Gesick.
CSC 113 Tutorial QUIZ I.
CMSC202 Computer Science II for Majors Lecture 04 – Pointers
Building Web Applications
Classes & Objects: Examples
Class Structure 7-Dec-18.
Advanced Java Programming
Object Oriented Programming
Class Structure 2-Jan-19.
Chapter 4 Topics: class declarations method declarations
Namespaces, Scopes, Access privileges
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Class Structure 25-Feb-19.
Data Structures & Algorithms
A Methodical Approach to Methods
Chapter (3) - Procedures
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”

Lecture 12 Log into Canvas Announcement re BIT 116 & BIT 142 Quiz Sit with your ICE 12 group! Put your name sticker on your computer Announcement re BIT 116 & BIT 142 Quiz Instance Variables ICE & Mid-Course Survey

Skipping BIT 116? Criteria for skipping BIT 116 for BIT 142: Solid performance in this class: 3.8+ GPA (93%+) Should reach this mark by the time A3 is graded Very comfortable / confident with the material Feel like you could handle more, at a faster rate BIT116: JavaScript is very useful! Front-End Development: Gmail Server-Side Development: node.js TAKE ATTENDANCE BIT 115: Introduction To Programming

Quiz12 5 minutes Regards ICE11’s Part 1 Passcode: ice11part1

Instance Variables Temporary/Local Variables versus Instance Variables All the local variables we've looked at so far will disappear at the end of the service. This means that they're temporary. We want memory that won't go away between method/service calls. We want the robot to remember something, to be able to keep a running tally that can be called up outside the scope of the method, not just get some temporary working space. An instance variable is what we need. A temporary variable can only be used inside the method where it is created. An instance variable may be used anywhere in the class containing it, by any of its methods We manage this by declaring it private, which is foreshadowing the beginnings of encapsulation (although we aren’t quite there yet)

Temporary Variables Class method1 method2 method3 main int a = 0; … int b=0; b=8; method3 int c=0; c=a+b; main method1(); method2(); method3(); Temporary Variables Suppose we want to recall a number from one method to use in a different method? With local (or temporary) variables we can’t do that since the variable space is no longer available once we leave the method This does not work as planned because int a and int b are not available to method3 So how do we get around this limitation of local variables?

We Do It With Instance Variables Class private int a=0; private int b=0; private int c=0; method1 … a=4 method2 b=8; method3 c=a+b; main method1(); method2(); method3(); We Do It With Instance Variables We declare the variables inside the class but outside the methods, that way all the methods can access and use them We also declare them as private so only objects instantiated from the class that declared them can use and/or alter them, protecting them from outside interference (hence, private).

We Do It With Instance Variables Class private int a=0; private int b=0; private int c=0; method1 … a=4 method2 b=8; method3 c=a+b; // 12=4+8 main method1(); method2(); method3(); We Do It With Instance Variables We declare the variables inside the class but outside the methods, that way all the methods can access and use them See: InstVar_Demo_1.java InstVar_Demo_2.java

Adding Another Argument to Constructor Useful when you create a new robot Object with other functionality besides just its placement in the City Let’s say you want to create a new type of Robot that also starts with a limited number of actions it’s allowed to do when the program is run, say for example, 20 total actions. You can add another argument to its parameters to hold this number (although you’ll still have to write the code to actually do something with this number)! You would create a new class that extends the Robot class You could create an instance variable to hold data You could create a new argument in the constructor’s parameter to enter this additional data You could assign this entered data inside the constructor to the instance variable to be used elsewhere in the program for whatever purposes you need Example on Next Page 

ExampleNewArgument.java class RechargableRobot extends Robot { private int numOfActions; // number of actions executed instance-variable private int maxNumOfActions; // max number of actions instance-variable RechargableRobot( City c, int st, int ave, Direction dir, int num, int numActions) super(c, st, ave, dir, num); //  Notice NO additional argument here for the superclass this.maxNumOfActions = numActions; // set the max number of actions } // Additional Methods go here public class ExampleNewArgument extends Object public static void main(String[] args) City toronto = new City(); RechargableRobot Jo = new RechargableRobot(toronto, 3, 0, Direction.EAST, 0, 10); new Thing(toronto, 3, 2); // Additional Code goes here

Time ICE12 Work on the same computer with your Canvas ICE12 group! Don’t forget to do your Mid-Course Survey by 11:59pm tonight!