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 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)
4
Creating a class
5
Creating a class class nameOfClass {
members of the class (fields, properties, methods) }
6
Creating a class class nameOfClass {
members of the class (fields, properties, methods) }
7
Creating a class…adding fields
class MyClass { private int intField; private string strField; public int MyMethod(string strInputVariable) }
8
Creating a class…adding fields
class MyClass { private int intField; private string strField; public int MyMethod(string strInputVariable) }
9
Creating a class…adding fields
class MyClass { private int intField; private string strField; public int MyMethod(string strInputVariable) }
10
Creating a class…adding fields
class MyClass { private int intField; private string strField; public int MyMethod(string strInputVariable) }
11
Properties
12
Properties Smart fields
13
Properties Smart fields Always is paired with a field
14
Properties Smart fields Always is paired with a field
Written like a method
15
Properties Smart fields Always is paired with a field
Written like a method Used like a variable
16
Properties
17
Properties Field:
18
Properties Field: Private
19
Properties Field: Private
Name starts with lower case (it is a variable)
20
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property:
21
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public
22
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method)
23
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method) Two parts:
24
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method) Two parts: get
25
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method) Two parts: get … “get” or read the field’s value
26
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method) Two parts: get … “get” or read the field’s value set
27
Properties Field: Property: Private
Name starts with lower case (it is a variable) Property: Public Name is same as field except upper case (it is like a method) Two parts: get … “get” or read the field’s value set … “set” or assign the field’s value
28
Creating a class… adding properties
29
Creating a class… adding properties
class MyClass { } private int myField; public int MyField get return myField; } set myField = value;
30
Creating a class… adding properties
class MyClass { private int myField; } public int MyField get return myField; } set myField = value;
31
Creating a class… adding properties
class MyClass { private int myField; public int MyField } get } { return myField; } set myField = value;
32
Creating a class… adding properties
class MyClass { private int myField; public int MyField get } return myField; } } } set myField = value; }
33
Creating a class… adding properties
class MyClass { private int myField; public int MyField get return myField; } } set } { myField = value;
34
Creating a class… adding properties
class MyClass { private int myField; public int MyField get return myField; } set } myField = value;
35
Creating a class… adding properties
class MyClass { private int myField; public int MyField get return myField; } set myField = value;
36
Using Properties
37
Using Properties int fieldValue; // a local variable to play with
38
Using Properties int fieldValue; // a local variable to play with
MyClass obj = new MyClass(); // create an instance of MyClass
39
Using Properties int fieldValue; // a local variable to play with
MyClass obj = new MyClass(); // create an instance of MyClass …
40
Using Properties int fieldValue; // a local variable to play with
MyClass obj = new MyClass(); // create an instance of MyClass … obj.MyField = 17; // assign a value to the property (set)
41
Using Properties int fieldValue; // a local variable to play with
MyClass obj = new MyClass(); // create an instance of MyClass … obj.MyField = 17; // assign a value to the property (set)
42
Using Properties int fieldValue; // a local variable to play with
MyClass obj = new MyClass(); // create an instance of MyClass … obj.MyField = 17; // assign a value to the property (set) fieldValue = obj.MyField; // use the property’s value (get)
43
Your task
44
Your task Using your GetUserInput class from last week (PigLatinXlate project)
45
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties:
46
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string)
47
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int)
48
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int) Do not make the properties static
49
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int) Do not make the properties static Change your GetMenuSelection method:
50
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int) Do not make the properties static Change your GetMenuSelection method: Use these fields instead of input variables
51
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int) Do not make the properties static Change your GetMenuSelection method: Use these fields instead of input variables Change your Main method:
52
Your task Using your GetUserInput class from last week (PigLatinXlate project) Add two fields and associated properties: menuDisplayMsg (string) numMenuOptions (int) Do not make the properties static Change your GetMenuSelection method: Use these fields instead of input variables Change your Main method: Use the new properties and GetMenuSelection method
53
Follow-on Task Change the NumMenuOptions property to be read-only:
Remove its set method Change the MenuDisplayMsg property: Calculate the number of menu options by counting the “)” characters in the display message string. Set the numMenuOptions field with that number.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.