Download presentation
Presentation is loading. Please wait.
1
2006 Pearson Education, Inc. All rights reserved. 1 3 3 Introduction to C# Applications
2
2006 Pearson Education, Inc. All rights reserved. 2 When faced with a decision, I always ask, “What would be the most fun?” — Peggy Walker What’s in a name? That which we call a rose by any other name would smell as sweet. — William Shakespeare
3
2006 Pearson Education, Inc. All rights reserved. 3 “Take some more tea,” the March Hare said to Alice, very earnestly. “I’ve had nothing yet.” Alice replied in an offended tone, “So I can’t take more.” “You mean you can’t take less,” said the Hatter, “it’s very easy to take more than nothing.” — Lewis Carroll
4
2006 Pearson Education, Inc. All rights reserved. 4 OBJECTIVES In this chapter you will learn: To write simple C# applications using code rather than visual programming. To write statements that input and output data to the screen. To declare and use data of various types. To store and retrieve data from memory. To use arithmetic operators. To determine the order in which operators are applied. To write decision-making statements. To use relational and equality operators. To use message dialogs to display messages.
5
2006 Pearson Education, Inc. All rights reserved. 5 3.1 Introduction 3.2 A Simple C# Application: Displaying a Line of Text 3.3Creating Your Simple Application in Visual C# Express 3.4 Modifying Your Simple C# Application 3.5 Formatting Text with Console.Write and Console.WriteLine 3.6 Another C# Application: Adding Integers 3.7 Memory Concepts 3.8 Arithmetic 3.9 Decision Making: Equality and Relational Operators 3.10 (Optional) Software Engineering Case Study: Examining the ATM Requirements Document 3.11 Wrap-Up
6
2006 Pearson Education, Inc. All rights reserved. 6 3.1 Introduction Console Application ─Input and output text in console window Windows 95/98/ME: MS-DOS prompt Other version of Windows: Command Prompt
7
2006 Pearson Education, Inc. All rights reserved. 7 3.2 A Simple C# Application: Displaying a Line of Text Sample program ─Displays a line of text ─Illustrates several important C# language features
8
2006 Pearson Education, Inc. All rights reserved. 8 Outline Welcome1.cs
9
2006 Pearson Education, Inc. All rights reserved. 9 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) ─Comments start with: // Comments ignored during program execution Document and describe code Provides code readability ─Traditional comments: /*... */ ─Another line of comments ─Note: line numbers not part of program, added for reference /* This is a traditional comment. It can be split over many lines. */ 1 // Fig. 3.1: Welcome1.cs 2 // Text-printing application.
10
2006 Pearson Education, Inc. All rights reserved. 10 Common Programming Error 3.1 Forgetting one of the delimiters of a delimited comment is a syntax error. The syntax of a programming language specifies the rules for creating a proper application in that language. A syntax error occurs when the compiler encounters code that violates C#’s language rules. In this case, the compiler does not produce an executable file. Instead, the compiler issues one or more error messages to help you identify and fix the incorrect code. Syntax errors are also called compiler errors, compile-time errors or compilation errors, because the compiler detects them during the compilation phase. You will be unable to execute your application until you correct all the syntax errors in it.
11
2006 Pearson Education, Inc. All rights reserved. 11 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) Keyword: using ─Helps the compiler locate a class that program will use ─Identifies pre-defined class Classes are organized under namespaces ─Named collection of related classes ─.NET’s namespaces are referred as Framework Class Library (FCL) 3 using System;
12
2006 Pearson Education, Inc. All rights reserved. 12 Common Programming Error 3.2 All using directives must appear before any other code (except comments) in a C# source code file; otherwise a compilation error occurs.
13
2006 Pearson Education, Inc. All rights reserved. 13 Error-Prevention Tip 3.1 Forgetting to include a using directive for a class used in your application typically results in a compilation error containing a message such as " The name ' Console ' does not exist in the current context." When this occurs, check that you provided the proper using directives and that the names in the using directives are spelled correctly, including proper use of uppercase and lowercase letters.
14
2006 Pearson Education, Inc. All rights reserved. 14 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) Blank line ─Makes program more readable ─Blank lines, spaces, and tabs are white-space characters ─Ignored by compiler Begins class declaration for class Welcome1 ─Every C# program has at least one user-defined class ─Keyword: words reserved for use by C# class keyword followed by class name ─Naming classes: capitalize every word (Pascal casting) SampleClassName 4 5 public class Welcome1
15
2006 Pearson Education, Inc. All rights reserved. 15 Good Programming Practice 3.1 By convention, always begin a class name’s identifier with a capital letter and start each subsequent word in the identifier with a capital letter.
16
2006 Pearson Education, Inc. All rights reserved. 16 Fig. 3.2 | C# keywords.
17
2006 Pearson Education, Inc. All rights reserved. 17 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) ─C# identifier Series of characters consisting of letters, digits and underscores ( _ ) Does not begin with a digit, has no spaces Examples: Welcome1, identifier, _value, button7 ─ 7button is invalid C# is case sensitive (capitalization matters) ─ a1 and A1 are different ─In chapters 3 to 8, use public class Certain details not important now Mimic certain features, discussions later
18
2006 Pearson Education, Inc. All rights reserved. 18 Common Programming Error 3.3 C# is case sensitive. Not using the proper uppercase and lowercase letters for an identifier normally causes a compilation error.
19
2006 Pearson Education, Inc. All rights reserved. 19 Good Programming Practice 3.2 By convention, a file that contains a single public class should have a name that is identical to the class name (plus the.cs extension) in terms of both spelling and capitalization. Naming your files in this way makes it easier for other programmers (and you) to determine where the classes of an application are located.
20
2006 Pearson Education, Inc. All rights reserved. 20 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) ─Saving files File name must be class name with.cs extension Welcome1.cs ─Left brace { Begins body of every class } Right brace ends declarations 6 { 12 } // end class Welcome1
21
2006 Pearson Education, Inc. All rights reserved. 21 Error-Prevention Tip 3.2 Whenever you type an opening left brace, {, in your application, immediately type the closing right brace, }, then reposition the cursor between the braces and indent to begin typing the body. This practice helps prevent errors due to missing braces.
22
2006 Pearson Education, Inc. All rights reserved. 22 Good Programming Practice 3.3 Indent the entire body of each class declaration one “level” of indentation between the left and right braces that delimit the body of the class. This format emphasizes the class declaration’s structure and makes it easier to read. You can let the IDE format your code by selecting Edit > Advanced > Format Document.
23
2006 Pearson Education, Inc. All rights reserved. 23 Good Programming Practice 3.4 Set a convention for the indent size you prefer, then uniformly apply that convention. The Tab key may be used to create indents, but tab stops vary among text editors. We recommend using three spaces to form each level of indentation. We show how to do this in Section 3.3.
24
2006 Pearson Education, Inc. All rights reserved. 24 Common Programming Error 3.4 It is a syntax error if braces do not occur in matching pairs.
25
2006 Pearson Education, Inc. All rights reserved. 25 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) ─Part of every C# application Applications begin executing at Main ─Parentheses indicate Main is a method (Ch. 3 and 6) ─C# applications contain one or more methods Exactly one method must be called Main ─Methods can perform tasks and return information void means Main returns no information For now, mimic Main 's first line 7 public static void Main( string[] args ) ─Part of every C# application Applications begin executing at Main ─Parentheses indicate Main is a method (Ch. 3 and 6) ─C# applications contain one or more methods Exactly one method must be called Main ─Methods can perform tasks and return information void means Main returns no information For now, mimic Main 's first line 7 public static void Main( string[] args )
26
2006 Pearson Education, Inc. All rights reserved. 26 Good Programming Practice 3.5 As with class declarations, indent the entire body of each method declaration one “level” of indentation between the left and right braces that define the method body. This format makes the structure of the method stand out and makes the method declaration easier to read.
27
2006 Pearson Education, Inc. All rights reserved. 27 3.2 A Simple C# Application: Displaying a Line of Text (Cont.) ─Instructs computer to perform an action Prints string of characters ─String: series characters inside double quotes White-spaces in strings are not ignored by compiler ─Method Console.WriteLine Standard output Print to command window (i.e., MS-DOS prompt) Displays line of text ─This line is known as a statement Statements must end with semicolon ; 10 Console.WriteLine( "Welcome to C# Programming!" );
28
2006 Pearson Education, Inc. All rights reserved. 28 Common Programming Error 3.5 Omitting the semicolon at the end of a statement is a syntax error.
29
2006 Pearson Education, Inc. All rights reserved. 29 Error-Prevention Tip 3.3 When learning how to program, sometimes it is helpful to “break” a working application so you can familiarize yourself with the compiler’s syntax-error messages. Try removing a semicolon or brace from the code of Fig. 3.1, then recompiling the application to see the error messages generated by the omission.
30
2006 Pearson Education, Inc. All rights reserved. 30 Error-Prevention Tip 3.4 When the compiler reports a syntax error, the error may not be in the line indicated by the error message. First, check the line for which the error was reported. If that line does not contain syntax errors, check several preceding lines.
31
2006 Pearson Education, Inc. All rights reserved. 31 Good Programming Practice 3.6 Following the closing right brace of a method body or class declaration with a comment indicating the method or class declaration to which the brace belongs improves application readability.
32
2006 Pearson Education, Inc. All rights reserved. 32 3.3 Creating Your Simple Application in Visual C# Express Creating the Console Application ─Open New Project dialog and select Console Application (Fig. 3.3-3.4) Modifying the Editor Settings ─Visual C# Express provides many ways to personalize your coding experience (Fig. 3.5) Changing the Name of the Application File ─Change the File Name property in the Solution Explorer (Fig. 3.6)
33
2006 Pearson Education, Inc. All rights reserved. 33 Project name Fig. 3.3 | Creating a Console Application with the New Project dialog.
34
2006 Pearson Education, Inc. All rights reserved. 34 Editor window Fig. 3.4 | IDE with an open console application.
35
2006 Pearson Education, Inc. All rights reserved. 35 Fig. 3.5 | Modifying the IDE settings.
36
2006 Pearson Education, Inc. All rights reserved. 36 Solution Explorer Properties window File Name Property Click Program.cs to display its properties Type Welcome1.cs here to rename the file Fig. 3.6 | Renaming the program file in the Properties window.
37
2006 Pearson Education, Inc. All rights reserved. 37 3.3 Creating Your Simple Application in Visual C# Express (Cont.) Writing Code ─IntelliSense: Lists a class’s members after a dot (Fig. 3.7-3.8) Saving the Application ─Specify the directory where you want to save this project (Fig. 3.9) Compiling and Running the Application ─Compiler compiles code into files (Fig. 3.10) Ex:.exe (executable),.dll (dynamic link library), and more! Running the Application from the Command Prompt ─Alternate way to go run a program without using the IDE (Fig. 3.11-3.12)
38
2006 Pearson Education, Inc. All rights reserved. 38 Partially-typed member Member list Highlighted member Tool tip describes highlighted member Fig. 3.7 | IntelliSense feature of Visual C# Express.
39
2006 Pearson Education, Inc. All rights reserved. 39 Up arrow Down arrow Parameter Info window Fig. 3.8 | Parameter Info window.
40
2006 Pearson Education, Inc. All rights reserved. 40 Fig. 3.9 | Save Project dialog.
41
2006 Pearson Education, Inc. All rights reserved. 41 Console window Fig. 3.10 | Executing the application shown in Fig. 3.1.
42
2006 Pearson Education, Inc. All rights reserved. 42 Default prompt displays when Command Prompt is opened User enters the next command here Fig. 3.11 | Executing the application shown in Fig. 3.1 from a Command Prompt window.
43
2006 Pearson Education, Inc. All rights reserved. 43 Application’s output Closes the Command Prompt window Type this to run the Welcome1.exe application Updated prompt showing the new current directory Type this to change to the application’s directory Fig. 3.12 | Executing the application shown in Fig. 3.1 from a Command Prompt window.
44
2006 Pearson Education, Inc. All rights reserved. 44 3.3 Creating Your Simple Application in Visual C# Express (Cont.) Syntax Errors, Error Messages and the Error List Window ─Syntax Error A violation of Visual C# rules for creating correct application ─Error List Window (Fig. 3.13) Window where the descriptions of the errors are located Note: Red underline indicts a syntax error
45
2006 Pearson Education, Inc. All rights reserved. 45 Intentionally omitted parenthesis character (syntax error) Red underline indicates a syntax errorError List window Error description(s) Fig. 3.13 | Syntax errors indicated by the IDE.
46
2006 Pearson Education, Inc. All rights reserved. 46 Error-Prevention Tip 3.5 One syntax error can lead to multiple entries in the Error List window. Each error that you address could eliminate several subsequent error messages when you recompile your application. So when you see an error you know how to fix, correct it and recompile—this may make several other errors disappear.
47
2006 Pearson Education, Inc. All rights reserved. 47 3.4 Modifying Your Simple C# Application Modifying program ─ Welcome2.cs (Fig. 3.14) produces same output as Welcome1.cs (Fig. 3.1) ─Using different code ─Line 10 displays “Welcome to ” with cursor remaining on printed line ─Line 11 displays “C# Programming! ” on same line with cursor on next line 10 Console.Write( "Welcome to "); 11 Console.WriteLine( “ C# Programming!" );
48
2006 Pearson Education, Inc. All rights reserved. 48 Outline Welcome2.cs Cursor stays on same line after outputting Cursor moves to next line after outputting
49
2006 Pearson Education, Inc. All rights reserved. 49 3.4 Modifying Your Simple C# Application (Cont.) Escape characters ─Backslash ( \ ) ─Indicates special characters be output Newline characters ( \n ) ─Interpreted as “special characters” by methods Console.Write and Console.WriteLine ─Indicates cursor should be at the beginning of the next line ─ Welcome3.cs (Fig. 3.15) ─Line breaks at \n 10 Console.WriteLine( “ Welcome\nto\nC#\nProgramming!" );
50
2006 Pearson Education, Inc. All rights reserved. 50 Outline Welcome3.cs Notice how a new line is output for each \n escape sequence.
51
2006 Pearson Education, Inc. All rights reserved. 51 Fig. 3.16 | Some common escape sequences.
52
2006 Pearson Education, Inc. All rights reserved. 52 3.5 Formatting Text with Console.Write and Console.WriteLine Formatted Data ─Arguments are separated with commas ─WriteLine’s first argument is format string Fixed text: Regular text that is outputted Format items: Placeholder for a value ─Ex: {0} is the placeholder for the first argument 10 Console.WriteLine( “ {0}\n{1} ”, “ Welcome to ”, “ C# Programming ” );
53
2006 Pearson Education, Inc. All rights reserved. 53 Good Programming Practice 3.7 Place a space after each comma (,) in an argument list to make applications more readable.
54
2006 Pearson Education, Inc. All rights reserved. 54 Outline Welcome4.cs Console.WriteLine displays formatted data.
55
2006 Pearson Education, Inc. All rights reserved. 55 Common Programming Error 3.6 Splitting a statement in the middle of an identifier or a string is a syntax error.
56
2006 Pearson Education, Inc. All rights reserved. 56 3.6 Another C# Application: Adding Integers ─Begins public class Addition Recall that file name must be Addition.cs ─Lines 8-9: begins Main ─Variables Location in memory that stores a value ─Declare with name and type before use Variable name: any valid identifier ─Declarations end with semicolons ; ─Initialize variable in its declaration Equal sign 5 public class Addition 6 { 8 public static void Main( string[] args) 9 {
57
2006 Pearson Education, Inc. All rights reserved. 57 3.6 Another C# Application: Adding Integers (Cont.) ─Declare variable number1, number2 and sum of type int int holds integer values (whole numbers): i.e., 0, -4, 97 Types float, double and decimal can hold decimal numbers Type char can hold a single character: i.e., x, $, \n, 7 int, float, double, decimal and char are simple types ─Can add comments to describe purpose of variables ─Can declare multiple variables of the same type in one declaration Use comma-separated list 10 int number1; // first number to add 11 int number2; // second number to add 12 int sum; // second number to add int number1, // first number to add number2, // second number to add sum; // second number to add
58
2006 Pearson Education, Inc. All rights reserved. 58 Outline Addition.cs using declaration imports necessary components from the System namespace. Declare variables number1, number2 and sum. Convert user’s input into an int, and assign it to number1. Convert user’s next input into an int, and assign it to number2. Calculate the sum of the variables number1 and number2, assign result to sum. Display the sum using formatted output.
59
2006 Pearson Education, Inc. All rights reserved. 59 Good Programming Practice 3.8 Declare each variable on a separate line. This format allows a comment to be easily inserted next to each declaration.
60
2006 Pearson Education, Inc. All rights reserved. 60 Good Programming Practice 3.9 Choosing meaningful variable names helps code to be self-documenting (i.e., one can understand the code simply by reading it rather than by reading documentation manuals or viewing an excessive number of comments).
61
2006 Pearson Education, Inc. All rights reserved. 61 Good Programming Practice 3.10 By convention, variable-name identifiers begin with a lowercase letter, and every word in the name after the first word begins with a capital letter. This naming convention is known as camel casing.
62
2006 Pearson Education, Inc. All rights reserved. 62 3.6 Another C# Application: Adding Integers (Cont.) ─Message called a prompt: directs user to perform an action ─ ReadLine waits for user to type a string of characters ─ Convert.ToInt32 method converts the sequence of characters into data of type int ─Result of call to ReadLine given to number1 using assignment operator = Assignment statement = is a binary operator - takes two operands ─Expression on right evaluated and assigned to variable on left Read as: number1 gets the value of Convert.ToInt32( Console.ReadLine() ); 14 Console.Write( "Enter first integer: " ); // prompt user 16 number1 = Convert.ToInt32( Console.ReadLine() );
63
2006 Pearson Education, Inc. All rights reserved. 63 Good Programming Practice 3.11 Place spaces on either side of a binary operator to make it stand out and make the code more readable.
64
2006 Pearson Education, Inc. All rights reserved. 64 3.6 Another C# Application: Adding Integers (Cont.) ─Similar to previous statement Prompts the user to input the second integer ─Similar to previous statement Assign variable number2 to second integer input ─Assignment statement Calculates sum of number1 and number2 (right hand side) Uses assignment operator = to assign result to variable sum Read as: sum gets the value of number1 + number2 number1 and number2 are operands 18 Console.Write( "Enter second integer: " ); // prompt user 20 number2 = Convert.ToInt32( (Console.ReadLine() ); 22 sum = number1 + number2; // add numbers
65
2006 Pearson Education, Inc. All rights reserved. 65 3.6 Another C# Application: Adding Integers (Cont.) ─Use Console.WriteLine to display results ─{0} is placeholder for sum ─Calculations can also be performed inside WriteLine ─Parentheses around the expression number1 + number2 are not required 24 Console.WriteLine( "Sum is {0}: ", sum ); // display sum Console.WriteLine( "Sum is {0} ", ( number1 + number2 ) );
66
2006 Pearson Education, Inc. All rights reserved. 66 3.7 Memory Concepts Variables ─Every variable has a name, a type, a size and a value Name corresponds to location in memory ─When new value is placed into a variable, replaces (and destroys) previous value ─Reading variables from memory does not change them
67
2006 Pearson Education, Inc. All rights reserved. 67 Fig. 3.19 | Memory location showing the name and value of variable number1.
68
2006 Pearson Education, Inc. All rights reserved. 68 Fig. 3.20 | Memory locations after storing values for number1 and number2.
69
2006 Pearson Education, Inc. All rights reserved. 69 Fig. 3.21 | Memory locations after calculating and storing the sum of number1 and number2.
70
2006 Pearson Education, Inc. All rights reserved. 70 3.8 Arithmetic Arithmetic calculations used in most programs ─Usage * for multiplication / for division % for remainder +, - ─Integer division truncates remainder 7 / 5 evaluates to 1 ─Remainder operator % returns the remainder 7 % 5 evaluates to 2
71
2006 Pearson Education, Inc. All rights reserved. 71 Fig. 3.22 | Arithmetic operators.
72
2006 Pearson Education, Inc. All rights reserved. 72 3.8 Arithmetic (Cont.) Operator precedence ─Some arithmetic operators act before others (i.e., multiplication before addition) Use parenthesis when needed or for clarity ─Example: Find the average of three variables a, b and c Do not use: a + b + c / 3 Use: ( a + b + c ) / 3
73
2006 Pearson Education, Inc. All rights reserved. 73 Fig. 3.23 | Precedence of arithmetic operators.
74
2006 Pearson Education, Inc. All rights reserved. 74 Fig. 3.24 | Order in which a second-degree polynomial is evaluated.
75
2006 Pearson Education, Inc. All rights reserved. 75 3.9 Decision Making: Equality and Relational Operators Condition ─Expression can be either true or false if statement ─Simple version in this section, more detail later ─If a condition is true, then the body of the if statement executed ─Control always resumes after the if statement ─Conditions in if statements can be formed using equality or relational operators (Fig. 3.25)
76
2006 Pearson Education, Inc. All rights reserved. 76 Fig. 3.25 | Equity and relational operators.
77
2006 Pearson Education, Inc. All rights reserved. 77 Outline Comparison.cs (1 of 2) Test for equality, display result using WriteLine. Compares two numbers using relational operator <.
78
2006 Pearson Education, Inc. All rights reserved. 78 Outline Comparison.cs (2 of 2) Compares two numbers using relational operator >, =.
79
2006 Pearson Education, Inc. All rights reserved. 79 3.9 Decision Making: Equality and Relational Operators (Cont.) ─Line 6: begins class Comparison declaration ─Lines 11-12: declare int variables ─Lines 15-16: prompt the user to enter the first integer and input the value ─Lines 19-20: prompt the user to enter the second integer and input the value
80
2006 Pearson Education, Inc. All rights reserved. 80 3.9 Decision Making: Equality and Relational Operators (Cont.) ─ if statement to test for equality using ( == ) If variables equal (condition true) ─Line 23 executes If variables not equal, statement skipped No semicolon at the end of if statement Empty statement ─No task is performed ─Lines 25-26, 28-29, 31-32, 34-35 and 37-38 Compare number1 and number2 with the operators !=,, =, respectively 22 if ( number1 == number2 ) 23 Console.WriteLine( “ {0} == {1}", number1, number2 );
81
2006 Pearson Education, Inc. All rights reserved. 81 Common Programming Error 3.7 Forgetting the left and/or right parentheses for the condition in an if statement is a syntax error—the parentheses are required.
82
2006 Pearson Education, Inc. All rights reserved. 82 Common Programming Error 3.8 Confusing the equality operator, ==, with the assignment operator, =, can cause a logic error or a syntax error. The equality operator should be read as “is equal to,” and the assignment operator should be read as “gets” or “gets the value of.” To avoid confusion, some people read the equality operator as “double equals” or “equals equals.”
83
2006 Pearson Education, Inc. All rights reserved. 83 Common Programming Error 3.9 It is a syntax error if the operators ==, !=, >= and = and < =, respectively.
84
2006 Pearson Education, Inc. All rights reserved. 84 Common Programming Error 3.10 Reversing the operators !=, >= and and =<, is a syntax error.
85
2006 Pearson Education, Inc. All rights reserved. 85 Good Programming Practice 3.12 Indent an if statement’s body to make it stand out and to enhance application readability.
86
2006 Pearson Education, Inc. All rights reserved. 86 Common Programming Error 3.11 Placing a semicolon immediately after the right parenthesis of the condition in an if statement is normally a logic error.
87
2006 Pearson Education, Inc. All rights reserved. 87 Good Programming Practice 3.13 Place no more than one statement per line in an application. This format enhances readability.
88
2006 Pearson Education, Inc. All rights reserved. 88 Good Programming Practice 3.14 A lengthy statement can be spread over several lines. If a single statement must be split across lines, choose breaking points that make sense, such as after a comma in a comma-separated list, or after an operator in a lengthy expression. If a statement is split across two or more lines, indent all subsequent lines until the end of the statement.
89
2006 Pearson Education, Inc. All rights reserved. 89 Good Programming Practice 3.15 Refer to the operator precedence chart (the complete chart is in Appendix A) when writing expressions containing many operators. Confirm that the operations in the expression are performed in the order you expect. If you are uncertain about the order of evaluation in a complex expression, use parentheses to force the order, as you would do in algebraic expressions. Observe that some operators, such as assignment, =, associate from right to left rather than from left to right.
90
2006 Pearson Education, Inc. All rights reserved. 90 Fig. 3.27 | Precedence and associatively of operations discussed.
91
2006 Pearson Education, Inc. All rights reserved. 91 3.10 (Optional) Software Engineering Case Study: Examining the Requirements Document Object-oriented design (OOD) process using UML ─Chapters 4 to 9, 11 Object-oriented programming (OOP) implementation ─Appendix J
92
2006 Pearson Education, Inc. All rights reserved. 92 Fig. 3.28 | Automated teller machine user interface.
93
2006 Pearson Education, Inc. All rights reserved. 93 Fig. 3.29 | ATM main menu.
94
2006 Pearson Education, Inc. All rights reserved. 94 Fig. 3.30 | ATM withdrawal menu.
95
2006 Pearson Education, Inc. All rights reserved. 95 3.10 (Optional) Software Engineering Case Study: Examining the Requirements Document (Cont.) Analyzing the ATM System ─Requirements gathering ─Software life cycle Waterfall model: Perform each stage once in succession Iterative model: Repeat one or more stages several times ─Use case modeling Use Case Diagram ─Model the interactions between clients and its use cases ─Actor External entity
96
2006 Pearson Education, Inc. All rights reserved. 96 Fig. 3.31 | Use case diagram for the ATM system from the user’s perspective.
97
2006 Pearson Education, Inc. All rights reserved. 97 Fig. 3.32 | Use case diagram for a modified version of our ATM system that allows users to transfer money between accounts.
98
2006 Pearson Education, Inc. All rights reserved. 98 3.10 (Optional) Software Engineering Case Study: Examining the Requirements Document (Cont.) UML diagram types (UML 2 specifies 13 diagram types) ─Model system structure and behavior Use case diagrams ─Model interactions between user and a system Class diagram ─Models classes, or “building blocks” of a system State machine diagrams ─Model the ways in which an object changes state Activity diagrams ─Models an object’s activity during program execution Communication diagrams (collaboration diagrams) ─Models the interactions among objects ─Emphasize what interactions occur Sequence diagrams ─Models the interactions among objects ─Emphasize when interactions occur
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.