Download presentation
Presentation is loading. Please wait.
1
Welcome back to Software Development!
2
Review – Class Members Do review slides
Finish MenuOption method project Instances and static Create UserInput class
3
Review – Class Members What are the three main types of class members?
4
Review – Class Members What are the three main types of class members?
Methods
5
Review – Class Members What are the three main types of class members?
Methods – class algorithms
6
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’
7
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields
8
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use
9
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use The data or information the class uses to do its job
10
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use The data or information the class uses to do its job Properties
11
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use The data or information the class uses to do its job Properties – “smart fields”
12
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables
13
Review – Class Members What are the three main types of class members?
Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables They “protect” the class variables (fields)
14
Review - Scope
15
Review - Scope What does scope mean?
16
Review - Scope What does scope mean?
The section of code a variable can be used in
17
Review - Scope What does scope mean?
The section of code a variable can be used in Defined by the current block { }
18
Review - Scope What does scope mean?
The section of code a variable can be used in Defined by the current block { } Inner blocks can see variables from outer blocks
19
Review - Scope What does scope mean?
The section of code a variable can be used in Defined by the current block { } Inner blocks can see variables from outer blocks Outer blocks can not see variables from inner blocks
20
Review – Scope Modifiers
21
Review – Scope Modifiers
We will call them access modifiers
22
Review – Scope Modifiers
We will call them access modifiers What are access modifiers?
23
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private
24
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private Control who has access to the members of a class
25
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private Control who has access to the members of a class public :
26
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private Control who has access to the members of a class public : everyone has access and can change
27
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private Control who has access to the members of a class public : everyone has access and can change private :
28
Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private Control who has access to the members of a class public : everyone has access and can change private : only members of same class have access and can change
29
The real, the original, the authentic Nestle Toll House Chocolate Chip Cookie Recipe
2 1/4 cups all-purpose flour 1 teaspoon baking soda 1 teaspoon salt 1 cup (2 sticks, 1/2 pound) butter, softened 3/4 cup granulated [white] sugar 3/4 cup packed brown sugar 1 teaspoon vanilla extract 2 eggs 2 cups (12-ounce package) NESTLE TOLL HOUSE Semi-Sweet Chocolate Morsels 1 cup chopped nuts COMBINE flour, baking soda and salt in small bowl. Beat butter, granulated sugar, brown sugar and vanilla in large mixer bowl. Add eggs one at a time, beating well after each addition; gradually beat in flour mixture. Stir in morsels and nuts. Drop by rounded tablespoon onto ungreased baking sheets. BAKE in preheated 375-degree [Fahrenheit] oven for 9 to 11 minutes or until golden brown. Let stand for 2 minutes; remove to wire racks to cool completely. PAN COOKIE VARIATION: PREPARE dough as above. Spread into greased 15"x10" jelly-roll pan. Bake in preheated 375-degree [Fahrenheit] oven for 20 to 25 minutes or until golden brown. Cool in pan on wire rack. FOR HIGH ALTITUDE BAKING (>5,200 feet): INCREASE flour to 2 1/2 cups; add 2 teaspoonfuls water with flour; reduce both granulated sugar and brown sugar to 2/3 cup each. Bake at 375 degrees Fahrenheit, drop cookies for 8 to 10 minutes and pan cookies for 17 to 19 minutes If I give this recipe to you, what good is it? Can you eat this recipe? No, you have to make a cookie from the recipe…
30
Instance
31
Instance A class is like a recipe
32
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…)
33
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie
34
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe
35
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe
36
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe Now you can “use” the cookie
37
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe Now you can “use” the cookie You have to create an instance of a class to use it…
38
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe Now you can “use” the cookie You have to create an instance of a class to use it… Except…
39
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe Now you can “use” the cookie You have to create an instance of a class to use it… Except…Unless…
40
Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie The cookie is an “instance” of the recipe You have “created” or “declared” a cookie from the recipe Now you can “use” the cookie You have to create an instance of a class to use it… Except…Unless…the some part of the class is useful all by itself…
41
The Coffee Pot Show coffee pot Ask what its function is Make coffee
Ask what you have to do to use that function Add water and coffee Can you make the coffee if you don’t add water and coffee grounds?
42
The Coffee Pot Think of a coffee pot as an object…
43
The Coffee Pot Think of a coffee pot as an object…a class
44
The Coffee Pot Think of a coffee pot as an object…a class
It has one method
45
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee()
46
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields
47
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater
48
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds
49
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work
50
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work Does this class have any use not requiring the fields?
51
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work Does this class have any use not requiring the fields? The glass pot can carry water…
52
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work Does this class have any use not requiring the fields? The glass pot can carry water…acts as a water pitcher
53
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work Does this class have any use not requiring the fields? The glass pot can carry water…acts as a water pitcher We have a new method
54
The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater 2) amountOfCoffeeGrounds The method needs the fields to work Does this class have any use not requiring the fields? The glass pot can carry water…acts as a water pitcher We have a new method – UseAsWaterPitcher()
55
Static Methods
56
Static Methods Some methods do not need to use any of the class fields
57
Static Methods Some methods do not need to use any of the class fields
These can be static methods
58
Static Methods Some methods do not need to use any of the class fields
These can be static methods Most methods do need to use some of the class fields
59
Static Methods Some methods do not need to use any of the class fields
These can be static methods Most methods do need to use some of the class fields These can not be static methods
60
Static Methods
61
Static Methods static
62
Static Methods static The keyword static means it doesn’t use any of the class fields
63
Static Methods static The keyword static means it doesn’t use any of the class fields You can use static methods without creating an instance of the class
64
Non-static Methods
65
Non-static Methods To use methods of a class that are not static…
66
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class
67
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new
68
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example:
69
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random…
70
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum;
71
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum; Variable name
72
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum; Variable type Variable name
73
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum; Variable type Variable name Declaring a variable named rndNum of type Random
74
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum; Variable type Variable name Declaring a variable named rndNum of type Random You have created the “recipe” … you haven’t baked the cookie yet
75
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum = new Random();
76
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum = new Random(); Create the recipe
77
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum = new Random(); Create the recipe Bake the cookie… …create an instance of the class Random as a variable
78
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum = new Random(); Create the recipe Bake the cookie… …create an instance of the class Random as a variable Keyword new is used to create an instance of a class
79
Non-static Methods To use methods of a class that are not static…
You must create an instance of the class … as a variable using keyword new Example: the class Random… Random rndNum = new Random(); int a = rndNum.Next(1, 20);
80
Creating a class
81
Creating a class class nameOfClass
82
Creating a class class nameOfClass {
members of the class (fields, properties, methods) }
83
Creating a class class nameOfClass {
members of the class (fields, properties, methods) }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.