Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome back to Software Development!

Similar presentations


Presentation on theme: "Welcome back to Software Development!"— Presentation transcript:

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 What the book calls “instance variables”

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 What the book calls “instance variables” The data or information the class uses to do its job

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 What the book calls “instance variables” The data or information the class uses to do its job Properties

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 What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields”

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 What the book calls “instance variables” 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

14 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 What the book calls “instance variables” 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)

15 Review - Scope

16 Review - Scope What does scope mean?

17 Review - Scope What does scope mean?
The section of code a variable can be used in

18 Review - Scope What does scope mean?
The section of code a variable can be used in Defined by the current block { }

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

20 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

21 Review – Scope Modifiers

22 Review – Scope Modifiers
We will call them access modifiers

23 Review – Scope Modifiers
We will call them access modifiers What are access modifiers?

24 Review – Scope Modifiers
We will call them access modifiers What are access modifiers? Keywords public and private

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

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 :

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

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 :

29 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

30 Reading Questions

31 Reading Questions What are scope modifiers (public/private)

32 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)?

33 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)?

34 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables?

35 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

36 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

37 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters? Properties that limit what can be done to a field

38 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters? Properties that limit what can be done to a field Yesterday’s example

39 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters? Properties that limit what can be done to a field Yesterday’s example Mario and Jackson “guarding” or “filtering” access to Jake’s grade

40 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

41 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

42 Reading Questions What are scope modifiers (public/private)
What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

43 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…

44 Instance

45 Instance A class is like a recipe

46 Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…)

47 Instance A class is like a recipe
You can’t eat the recipe (unless you like paper…) You have to make a cookie

48 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

49 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

50 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

51 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…

52 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…

53 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…

54 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…

55 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?

56 The Coffee Pot Think of a coffee pot as an object…

57 The Coffee Pot Think of a coffee pot as an object…a class

58 The Coffee Pot Think of a coffee pot as an object…a class
It has one method

59 The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee()

60 The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields

61 The Coffee Pot Think of a coffee pot as an object…a class
It has one method – MakeCoffee() It has two fields 1) amountOfWater

62 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

63 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

64 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?

65 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…

66 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

67 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

68 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()

69 Static Methods

70 Static Methods Some methods do not need to use any of the class fields

71 Static Methods Some methods do not need to use any of the class fields
Examples:

72 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods:

73 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo()

74 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString()

75 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString() GetNumber()

76 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString() GetNumber() GetMenuOption()

77 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString() GetNumber() GetMenuOption() These can be static methods

78 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString() GetNumber() GetMenuOption() These can be static methods Most methods do need to use some of the class fields

79 Static Methods Some methods do not need to use any of the class fields
Examples: Your “get user input” methods: HitEnterTo() GetString() GetNumber() GetMenuOption() These can be static methods Most methods do need to use some of the class fields These can not be static methods

80 Static Methods

81 Static Methods static

82 Static Methods static The keyword static means it doesn’t use any of the class fields

83 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

84 Non-static Methods

85 Non-static Methods To use methods of a class that are not static…

86 Non-static Methods To use methods of a class that are not static…
You must create an instance of the class

87 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

88 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:

89 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…

90 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;

91 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

92 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

93 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

94 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

95 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();

96 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

97 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

98 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

99 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);

100 Instance Variables

101 Instance Variables The term the book uses for fields

102 Instance Variables The term the book uses for fields
Fields are the variables of a class

103 Instance Variables The term the book uses for fields
Fields are the variables of a class You can’t use a class with fields unless you make an instance of the class

104 Instance Variables The term the book uses for fields
Fields are the variables of a class You can’t use a class with fields unless you make an instance of the class Hence…

105 Instance Variables The term the book uses for fields
Fields are the variables of a class You can’t use a class with fields unless you make an instance of the class Hence…instance variables

106 Instance Variables The term the book uses for fields
Fields are the variables of a class You can’t use a class with fields unless you make an instance of the class Hence…instance variables We will simply use the term fields

107 Creating a class

108 Creating a class class nameOfClass

109 Creating a class class nameOfClass {
members of the class (fields, properties, methods) }

110 Creating a class class nameOfClass {
members of the class (fields, properties, methods) }

111 Your task

112 Your task Make a class containing all your “get user input” methods

113 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput

114 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class

115 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static

116 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static It will have four methods in it:

117 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static It will have four methods in it: HitEnterTo()

118 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static It will have four methods in it: HitEnterTo() GetString()

119 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static It will have four methods in it: HitEnterTo() GetString() GetNumber()

120 Your task Make a class containing all your “get user input” methods
Name the class GetUserInput This will be a completely static class Every method in it will be static It will have four methods in it: HitEnterTo() GetString() GetNumber() GetMenuSelection()


Download ppt "Welcome back to Software Development!"

Similar presentations


Ads by Google