Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.

Similar presentations


Presentation on theme: "Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification."— Presentation transcript:

1 Chapter 1. The Phases of Software Development

2 Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification  Recognize quadratic, linear, and logarithmic runtime behavior in sample algorithm  Create and recognize test data that is appropriate for a problem  Contents  Specification, Design, Implementation  Running Time Analysis  Testing and Debugging

3 Data Structure 3 Data structure is  Collection of data, generally organized so that items can be stored and retrieved by some fixed techniques

4 Data Structure 4 The Phase of Software Development  Problem analysis understand the problem  Requirements definition specify what program will do  High- and low-level designhow it meets requirements  Implementation of designcode it  Testing and verification detect errors, show correct  Delivery turn over to customer  Operation use the program  Maintenancechange the program  Obsolescence

5 Data Structure 5 An Algorithm is  A procedure or sequence of instructions for solving a problem  Expressed in many different ways  In English, in a particular programming language  In a pseudo code

6 Data Structure 6 Design Technique  Decomposing the problem  Break down a task into a few subtask  Then decompose each subtask into smaller subtasks  Each subtask is implemented as a separate Java method (“function” or “Procedures”)  Produces a good final program  What makes a good decomposition?  Subtasks should help you produce short pseudocode  What are good subtasks?  Potential for code reuse  Possibility of future changes

7 Data Structure 7 How to write a specification  Tells what the method does, but not how it does its work  Information hiding : “knows only as much as you need, but no more…”  Procedural abstraction  Method specification Includes  Short introduction  Parameter description  Precondition  Returns condition or postcondition  “Throws” List

8 Data Structure 8 How to write a specification  Example) celsiusToFahrenheit public static double celsiusToFahrenheit(double c) Convert a temperature from Celsius degrees to Fahrenheit degrees Parameters: c – a temparature in Celsius degrees Preconditon: c >= -273.16 Returns: the temperature c converted to Fahrenheit degrees Throws: IllegalArgumentException Indicates that c is less than the smallest Celsius temperature (-273.16)

9 Data Structure 9 Precondition and Postcondition  Precondition  Is a statement giving the condition that is supposed to be true when a method is called  Postcondition  Is a statement describing what will be true when a method call is completed.  If the method is correct and the precondition was true when the method was called, then the method will complete

10 Data Structure 10 Precondition and Postcondition  Example // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. public void writeSqrt( double x)... The precondition and postcondition appear as comments in your program. They are usually placed before the method implementation.

11 Data Structure 11 Precondition and Postcondition  Another Example // Precondition: letter is an uppercase or // lowercase letter (in the range 'A'... 'Z' or 'a' //... ‘z'). // Postcondition: The value returned by the method is // true if letter is a vowel; otherwise the value // returned by the method is false. public boolean isVowel( char letter )... “Always make sure the precondition is valid...... so the postcondition becomes true at the method end.”

12 Data Structure 12 Exceptions  Exceptions  Messages for serious programming errors  Throwing an exception  The act of halting work and passing a message to the calling program Public static double celToFah(double c) { final double MINIMUM_CELSIUS = -273.16 ; if( c < MINIMUM_CELSIUS) throw new IllegalArgumentException(“Argument” + c + “is too small.”); return (9.0/5.0) * c + 32; }

13 Data Structure 13 Exception  Exception handling throw new ( “ “) This is the type of exception we are throwing. All of our exceptions will be the type IllegalArgumentException This is an error message that will be passed as part of the exception The message should describe the error well

14 Data Structure 14 Running Time Analysis  Time analysis  Consists of reasoning about an algorithm’s speed  Does the algorithm work fast enough for my needs?  How much longer does the algorithm take when the input gets larger?  The Stair-Counting Problem  You and Judy at the top of the Eiffel Tower  “How many steps there are to the bottom?”  There are Three Techniques for this problem !

15 Data Structure 15 Three techniques for the stair-counting problem  Technique 1: Walk Down and keep a Tally  Each time you take a step down, mark on the sheet of paper  Technique 2: Walk Down, but Let Judy keep the Tally  Each time you take a step down, Judy mark on the sheet of paper (step down, lay a hat, step up)  Technique 3: Jervis to the Rescue  Use the Jervis’s sign “There are 2689 steps” Actual elapsed time and vary depending on other factors So, Count certain operations

16 Data Structure 16 Analysis for the stair-counting problem  Certain operations for analysis  Walk up or down : one operation  Mark on the paper : one operation  Total operations of three techniques  Technique 1: 3 * 2689  Technique 2: downward steps = (1 + 2 + … + 2689) upward steps = (1 + 2 + … + 2689) marks made = 2689 7,236,099  Technique 3: 4

17 Data Structure 17 Time analysis  Similar to the analysis of the stair-counting techniques  Counts the number of operations  Depends on the program’s input  The time expressions for three techniques  Technique 1 : 3n  Technique 2 : n 2 + 2n  Technique 3 : log 10 n + 1

18 Data Structure 18 Big-O Notation  Quadratic Time  If the largest term is no more than a constant times n 2, the algorithm is “big-O of n 2, O(n 2 )  Doubling the input size makes the number of operations increase four fold  Linear Time  If the largest term is a constant times n, the algorithm is “big-O of n, O(n)  Doubling the input size makes the number of operations increase two fold  Logarithmic Time  If the largest term is a constant times a logarithm of n, the algorithm is “big-O of the logarithm of n, O(logn)

19 Data Structure 19 Big-O Notation  The Big-O notation of Three techniques  Technique 1 : O(n)  Technique 2 : O(n 2 )  Technique 3: O(logn) Order of the algorithm Big-O analysis loses some information about relative times

20 Data Structure 20 Time analysis of java methods public static boolean search(double[] data, double target) { int i; for ( i=0; i<data.length; i++ ) { if(data[i] == target) return true; } return false; }  Analysis parts  When the for-loop starts  Execute the body of loop  After the loop finishes  Analysis results  Total operations : Kn + 3  O(n)  Worst-case analysis  Average-case analysis  best-case analysis

21 Data Structure 21 Testing and Debugging  Program testing  Occurs when run a program and observe its behavior  How the program works for that particular input  How long the program takes to complete  Properties of Good test data  Must know output of each test input  Test inputs that are most likely to cause errors  Boundary Values  “One step away from different behavior”  Example) 0, 1 & -1

22 Data Structure 22 Testing and Debugging  Fully Exercising code  Each line of code is executed at least once  Profiler  Help fully exercise code  Indicates how many times each method was called  Using a Debugger  Track down the reason why a test case is failing

23 Data Structure 23 Testing and Debugging  Assert statements  Is boolean expressions that can be checked for validity while a program is running assert : “ “; This is boolean expression that we want to make sure is true at this point in the program This is an error message that will Be generated if the boolean expression is false

24 Data Structure 24 Testing and Debugging  Assert statements Public static int max0f3( int a, int b, int c ) { int answer; answer = a; if ( b > answer ) answer = b; if ( c > answer ) answer = c; assert (answer == a)|| (answer == b)|| (answer == c) : “max0f3 answer is not equal to one of the arguments”; assert (answer >= a)&&(answer >= b)&&(answer >= c) : “max0f3 answer is not equal to the largest argument”; return answer; }


Download ppt "Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification."

Similar presentations


Ads by Google