introduction to objectselm/teaching/121_s12/...58 java definitions class: a type for objects infant...
TRANSCRIPT
![Page 1: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/1.jpg)
Introduction to Objects January 31, 2012
CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers
Prof. Learned-Miller
![Page 2: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/2.jpg)
Logistics
1
![Page 3: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/3.jpg)
Email 1. Send emails through OWL, not directly to
me or TAs. 2. Include as much detail as possible
1. What exactly did you do? 2. What exact problem did you have? 3. Other info:
1. Machine type (Mac, PC, Linux) 2. Versions of software: Java 1.2, etc.
2
![Page 4: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/4.jpg)
Wrong way to do it Emails:
“Yo dude! My thing don’t work. Wazzup?”
“I can’t get DrJava to work.”
3
![Page 5: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/5.jpg)
Right way to do it Emails:
“Esteemed Prof., Master of all things Java, I have a Mac and after downloading and installing DrJava according to the instructions on the course web page, when I double click on the DrJava icon, nothing happens. Can you help?” 4
![Page 6: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/6.jpg)
Embedded Exercises: How to see your current totals
5
![Page 7: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/7.jpg)
Embedded Exercises: How to see your current totals
6
![Page 8: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/8.jpg)
Embedded Exercises: How to see your current totals
7
![Page 9: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/9.jpg)
Embedded Exercises: How to see your current totals
8
![Page 10: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/10.jpg)
Some reminders Previous lectures on course web page No late assignments accepted
Can drop 2 exercises, and 1 programming Video of lectures on line (thru OWL
menu).
9
![Page 11: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/11.jpg)
Assignments due today, 11:30pm!
10
![Page 12: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/12.jpg)
OWL and DrJava Problems If you are having DrJava Problems or
OWL problems, you better go to office hours today and get them resolved. Bring your computer to office hours if you can.
11
![Page 13: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/13.jpg)
More Assignments!
12
![Page 14: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/14.jpg)
13
The Bulletin Board Instructions under “resources” http://bb-edlab.cs.umass.edu/cs121_S12/ Off-campus access:
Username: cs121 Password: EL121p
Get an account:
![Page 15: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/15.jpg)
14
The Bulletin Board
![Page 16: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/16.jpg)
15
The Bulletin Board
![Page 17: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/17.jpg)
DO NOT POST CODE!
Go to office hours instead General questions only
The Bulletin Board
![Page 18: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/18.jpg)
17
Comments about “Name and Height” Write a program to print your name and
your height in centimeters. It’s just going to be a few println
statements, and one multiplication. You must do the multiplication in the
program.
![Page 19: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/19.jpg)
Back to Java
18
![Page 20: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/20.jpg)
19
The “main” method
1 public class Greetings{!2 public static void main(String[] args){!3 System.out.print("Hello ");!4 System.out.print("out ");!5 System.out.print("there");!6 }!7 }!
![Page 21: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/21.jpg)
20
The “main” method
1 public class Greetings{!2 public static void main(String[] args){!3 System.out.print("Hello ");!4 System.out.print("out ");!5 System.out.print("there");!6 }!7 }!
![Page 22: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/22.jpg)
21
The “main” method
1 public class Greetings{!2 public static void main(String[] args){!3 System.out.print("Hello ");!4 System.out.print("out ");!5 System.out.print("there");!6 }!7 }!
main is where the program starts
![Page 23: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/23.jpg)
Review
22
![Page 24: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/24.jpg)
23
Strings and numbers System.out.println(“Stuff I want to say.”);
Stuff I want to say. System.out.println(“Sch” + “wing”);
Schwing System.out.println(3+5);
8 System.out.println(“3+5”);
3+5
![Page 25: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/25.jpg)
24
Strings and numbers Mixtures of strings and numbers.
From left to right, combine strings and numbers. • number + number number • string + string string • number + string string • string + number string (how can you remember
this?)
What will this do? System.out.println(3+5+”a”+3+5);
![Page 26: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/26.jpg)
Terms you need to learn NOW! declarations variables, variable names, identifiers assignments types strings
Be prepared for an AVALANCHE of terminology. This is a huge part of computer science. 25
![Page 27: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/27.jpg)
26
Declarations, Types, and Variable Names int x; // An integer. String name; // A group characters. double mileage; // A decimal number.
![Page 28: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/28.jpg)
Types Native Types
int // An integer. String // A group of characters. double // A decimal number. char // A single character.
User-defined Types (objects!) Infant EriksFancyTaxForm
27
![Page 29: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/29.jpg)
28
Assignments x = 3; name = “Erik”;
![Page 30: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/30.jpg)
29
Combining declarations and assignments int x = 3; String name = “Erik”; double myDecimal = 123.456;
![Page 31: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/31.jpg)
30
10 Minutes with the Doctor “Play. Then predict.”
![Page 32: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/32.jpg)
31
The rest of today Classes, objects, attributes, methods, …
![Page 33: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/33.jpg)
32
Here is a program...
![Page 34: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/34.jpg)
33
Here is a program... Where does it start?
![Page 35: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/35.jpg)
34
Here is a program... Where does it start?
![Page 36: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/36.jpg)
35
Here is a program... Where does it start?
“main is where the program starts.”
![Page 37: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/37.jpg)
36
There are 5 statements inside the body of this program. Each statement can be thought of as a single step, or as a program itself. “Get some barbecue sauce.”
A single step or a whole recipe?
![Page 38: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/38.jpg)
37
Line 4: Create a “file folder” for an Infant. Record the name of the Infant as “Lizzie”. Record the age of the Infant as 4. Finally, make a name for the FOLDER, (not the infant), called myKid.
![Page 39: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/39.jpg)
38
Line 5: Go to the “file folder” called myKid. Get the number that was stored there for the Infant’s age. Store the age of the Infant in a variable called lizAge.
![Page 40: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/40.jpg)
39
Line 6: A println statement! Print something that says “my kid’s name is “, followed by the name of the Infant, which is stored in the “file folder” called myKid.
![Page 41: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/41.jpg)
40
Line 7: Go to the “file folder” called myKid, and do something that adds one month to the age of the kid in the folder.
![Page 42: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/42.jpg)
41
Line 8: Another println statement! Print out a string that says “my kids is now “, followed by the age of the Infant stored in the file folder myKid, followed by “ months”
![Page 43: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/43.jpg)
42
Objects To understand this program, we must
start to learn about objects.
We are going to start by thinking of objects as “containers” of information.
![Page 44: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/44.jpg)
43
Containers Box:
Contains stuff Briefcase
Contains office papers and office supplies Folder
Contains papers and forms Form
“Contains” information
![Page 45: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/45.jpg)
44
Containers (continued) Individual containers: (instances)
A specific box A specific briefcase A specific form
A class of containers: (types) Shoe boxes for Nike Air Treads Gucci briefcases for 2012 1040EZ Federal income tax form for 2011
![Page 46: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/46.jpg)
45
Quiz
How many classes, how many instances?
![Page 47: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/47.jpg)
46
Quiz
Answers: 3 CLASSES of containers. 6 INSTANCES of containers.
![Page 48: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/48.jpg)
47
Today’s featured container
![Page 49: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/49.jpg)
Where do containers come from?
48
![Page 50: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/50.jpg)
Where do containers come from? Answer: They must be designed.
49
![Page 51: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/51.jpg)
50
Container designers Pocketbook designer for Gucci
A place for glasses? Make-up kit?… Backpack designer for NorthFace
How many bottle holders? How many sub-compartments?
Forms designer for IRS? Place for SSN? For current residence?
![Page 52: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/52.jpg)
You will be... Designing containers (types of objects) by
creating classes in Java. Creating instances of objects using the
classes that you designed, or that someone else designed.
Using the instances of objects by storing information, retrieving information, and doing other things with them.
51
![Page 53: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/53.jpg)
52
![Page 54: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/54.jpg)
53
Designing a container
Making an instance
Storing info
Retrieving stuff
Storing stuff Using the instance
Using the instance
Declaring an instance Specifying a class Retrieving
info
Other methods
A new model of briefcases
Change infant age
Store Infant age Make an instance:
myKid Define “Infant” Class
Fill briefcase with stuff
Create one briefcase
And take stuff out
![Page 55: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/55.jpg)
54
Objects A way of staying organized.
“Containers” for information. Kind of like file folders.
Anywhere you can put information or store information.
Other examples: • Cardboard storage boxes • File cabinet • Name and address form • Tax form
Why do we use “containers”?
![Page 56: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/56.jpg)
55
Imagine an Office with No File Folders “Please get me Erik’s address…
and Erik’s medical history… and Erik’s dental insurance… and Erik’s financial records… and ….”
Folders allow commands like: “Get me all of Erik’s information”
![Page 57: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/57.jpg)
56
Programs without objects
![Page 58: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/58.jpg)
57
Programs with Objects Person Erik; Person Vidit; Person Armita;
What information do we have on Armita? • Armita.LastName=“Kaboli”; • Armita.Age=26; • Armita.HeightInInches=65;
![Page 59: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/59.jpg)
58
Java definitions Class: a type for objects
Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of “CarRecord”)
Attribute: one place to store info in an object A slot for a pen in a briefcase A field for your first name in a form
Method: A way to tell the object to store or retrieve something, or do something else Remember this person’s name Give me this person’s age Figure out when this person was born and tell me.
![Page 60: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/60.jpg)
59
Java definitions Constructor: Create an instance of an object
Create one car from a car class Create one tax form from a tax form class
![Page 61: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/61.jpg)
60
![Page 62: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/62.jpg)
61
Design (or blueprint) of an object: The Definition
![Page 63: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/63.jpg)
62
Design for an object: The Definition
![Page 64: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/64.jpg)
63
Attributes: properties of the object (places to put stuff)
![Page 65: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/65.jpg)
64
What’s public, private? Basically:
public : accessible from outside the class private : not accessible outside the class
![Page 66: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/66.jpg)
65
Methods: stuff the object can do.
![Page 67: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/67.jpg)
66
Methods: stuff the object can do.
![Page 68: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/68.jpg)
67
Methods: stuff the object can do.
![Page 69: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/69.jpg)
68
Constructor: A Special Method to Create the Object
![Page 70: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/70.jpg)
69
![Page 71: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/71.jpg)
70
Some Code
![Page 72: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/72.jpg)
71
Some Code
![Page 73: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/73.jpg)
72
Some Code
A Declaration Performing an Assignment Calling a Constructor
![Page 74: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/74.jpg)
73
Declarations and Assignments Infant myKid = new Infant("Liz",4);!!Could have done these separately: !!Infant myKid; Declaration!!myKid = new Infant("Liz",4); !
Assignment
![Page 75: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/75.jpg)
74
Declarations and Assignments Infant myKid = new Infant("Liz",4);!!Could have done these separately: !!Infant myKid; Declaration!!myKid = new Infant("Liz",4); !
Assignment
![Page 76: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/76.jpg)
75
Calling a method
![Page 77: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/77.jpg)
76
Something we recognize!
![Page 78: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/78.jpg)
77
Another method call
![Page 79: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/79.jpg)
78
Some Code
![Page 80: Introduction to Objectselm/Teaching/121_S12/...58 Java definitions Class: a type for objects Infant (think of “InfantRecord”) Person (think of “PersonRecord”) Car (think of](https://reader035.vdocument.in/reader035/viewer/2022071004/5fc16417eda0c65ef27aed90/html5/thumbnails/80.jpg)
That’s it for today