Download presentation
Presentation is loading. Please wait.
Published byAlejandro Hillery Modified over 10 years ago
1
1 / / / /
2
2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation Responsibilities] ( ) ( )
3
3 (Encapsulation) (Encapsulation) (private) (private) – – – (public) (public)
4
4 Card Card
5
5 CardDemo.Program (1/2) /* * * * 3/14/2009 * 3/14/2009 */ */ using System; namespace CardDemo { class Program class Program { static void Main(string[] args) static void Main(string[] args) {
6
6 CardDemo.Program (2/2) Card diamond_10 = new Card(); Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetSuit('d'); diamond_10.SetRank(10); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetRank()); } }}
7
7 CardDemo.Card (1/3) /* * * * 3/14/2009 * 3/14/2009 */ */ using System; namespace CardDemo { class Card class Card { private char suit; private char suit; private int rank; private int rank;
8
8 CardDemo.Card (2/3) public void SetSuit(char s) public void SetSuit(char s) { suit = s; suit = s; } public void SetRank(int r) public void SetRank(int r) { rank = r; rank = r; }
9
9 CardDemo.Card (3/3) public char GetSuit() public char GetSuit() { return suit; return suit; } public int GetRank() public int GetRank() { return rank; return rank; } }}
10
10 (1/6) (1/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() Diamond_10 suit rank diamond_10 class Card { private char suit; private char suit; private int rank; private int rank;......}
11
11 (2/6) (2/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() diamond_10 suit rank diamond_10 d class Card {...... public void SetSuit(char s) public void SetSuit(char s) { suit = s; suit = s; }......}
12
12 (Parameters, Arguments) (Parameters, Arguments) – (Formal Parameters) – (Actual Parameters)
13
13 d s Main SetSuit diamond_10 suit rank Program
14
14 static void Main(string[] args) {...... dimond_10.SetSuit( d ); class Card { private suit;... public void SetSuit( char s ) { suit = s; }... } }
15
15 (3/6) (3/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() diamond_10 suit rank diamond_10 d 10 class Card {...... public void SetRank(int r) public void SetRank(int r) { rank = r; rank = r; }......}
16
16 (4/6) (4/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() diamond_10 suit rank diamond_10 d 10 suitd class Card {...... public char GetSuit() public char GetSuit() { return suit; return suit; }......}
17
17 Main suit GetSuit suit rank diamond_10 Program
18
18 char suit = dimond_10.GetSuit(); static void Main(string[] args) { } }} }... class Card { private suit;... public char GetSuit() { return suit; }... }
19
19 (5/6) (5/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() diamond_10 suit rank diamond_10 d 10 suitd rank 10 class Card {...... public int GetRank() public int GetRank() { return rank; return rank; }}
20
20 (6/6) (6/6) Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetSuit(), diamond_10.GetRank()); diamond_10.GetRank()); Program.Main() diamond_10 suit rank diamond_10 d 10 suitd rank 10 > d 10 class Card {...... public char GetSuit() public char GetSuit() { return suit; return suit; } public int GetRank() public int GetRank() { return rank; return rank; }}
21
21 (Attribute, Property) (Attribute, Property) class Card { private char suit; private int rank; public void SetSuit(char s) { suit = s; } public void SetRank(int r) { rank = r; } public char GetSuit() { return suit; } public int GetRank() { return rank; } class Card { private char suit; private int rank; public char Suit { set { suit = value; } get { return suit; } } public int Rank { set { rank = value; } get { return rank; } }
22
22 Card diamond_10 = new Card(); diamond_10.Suit='d'; diamond_10.Rank=10; char suit = diamond_10.Suit; int rank = diamond_10.Rank; Console.WriteLine("{0}{1}", diamond_10.Suit, diamond_10.Rank); Card diamond_10 = new Card(); diamond_10.SetSuit('d'); diamond_10.SetRank(10); char suit = diamond_10.GetSuit(); int rank = diamond_10.GetRank(); Console.WriteLine("{0}{1}", diamond_10.GetSuit(), diamond_10.GetRank());
23
CardDemo CardDemo 23
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.