Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Program Development

Similar presentations


Presentation on theme: "Chapter 1 Program Development"— Presentation transcript:

1 Chapter 1 Program Development
Asserting Java © Rick Mercer

2 Outline Goals Understand an example of program development
Understand the characteristics of a good algorithm Understand how algorithmic patterns can help design programs

3 Program Development One program development strategy has these three steps: Analysis: Understand the problem Design: Organize the solution Implementation: Get the solution running Program development is the progression from analysis to design to implementation We'll see deliverables from all three phases deliverable: An item that indicates progress was made

4 Deliverables Analysis deliverable Design deliverable
A list of variable names and some test cases Design deliverable An algorithm that outlines a solution Implementation deliverable An executable program

5 Analysis Synonyms for analysis Activities inquiry, examination, study
Read and understand the problem statement. Name the pieces of information necessary to solve the problem these data names are part of the solution

6 Problem Need a program to compute the course grade ___________________
Name the data needed to compute an answer ___________________ ____________________ Name data to store the answer _____________

7 There is more to data than just names
The data are stored in variables Each variable that stores numeric data has a name has a value can be used in a variety of operations such as storing different values into the variable multiply *, divide /, add +, and subtract retrieve the value to be used in expressions display the value

8 To input or output? It help in the early programs if data is distinguished either as input or as output Input Information the user must supply to solve the problem Output Information the computer must display after the processing has occurred

9 Test cases help us understand the problem
A test case includes specific input data, and the output it should generate Problem: Find wholesale price given the markup and retail prices Test Case 1 markup Input (1.0 represents 100%) retailPrice Input wholesalePrice Output Test Case 2 markup Input (0.5 represents 50%) retailPrice Input wholesalePrice Output

10 Summary of Analysis Things to do during analysis
Read and understand the problem Pick variable names that represent the answer This is the output Decide what data the user must enter to get the answer—the input (the unknowns) Develop some test cases Create a document that summarizes the analysis

11 Other Problems as Analysis Deliverables

12 Design Synonyms of design: model, think, plan, devise, pattern, propose, outline We'll use these design tools: algorithms algorithmic patterns

13 Algorithms An algorithm is a set of activities that solves a problem
An algorithm must: list activities that must be performed list the activities in the proper order

14 Algorithm to Bake a Cake
A recipe (a.k.a. an algorithm) Preheat Oven Grease Pan Mix ingredients Place ingredients into pan place pan in oven remove pan after 35 minutes Switch some activities around ... what happens if …

15 Algorithmic Patterns Pattern: Anything shaped or designed to serve as a model or guide in making something else Algorithmic Pattern: Serves as a guide to help develop programs It represents a common type of action that occurs over and over again in programs A solution that can be used different contexts The Input/Process/Output (IPO) Pattern can be used This IPO pattern will be used in our first project

16 IPO Algorithmic Pattern
Pattern: Input/Process/Output (IPO) Problem: The program requires input data to generate the desired information Outline: 1. obtain input data from user 2. process input data 3. output the results

17 Patterns ala Alexander
"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice." From A Pattern Language, Christopher Alexander, Oxford University Press, 1977

18 Example of Algorithm Design
The design deliverable will be an algorithm The IPO patterns provides a guide to design a more specific algorithm (that is a bit sketchy) IPO Model IPO applied to Chapter 1 Case Study I)nput Obtain the items that count for 127A's P)rocess Compute the course grade O)utput Display the course grade

19 Refining Activities in algorithms
We often need to refine one or more activities (algorithm steps). For example, Compute the course grade might now be refined with the mathematical addition + and multiplication * symbols

20 Implementation Synonyms for Implementation
accomplishment, making good, execution Implementation deliverable: computer program

21 Example Translations Here are some pseudocode algorithm step translated into the Java programming language Display the value of courseGrade System.out.println("Course grade: " + courseGrade); Obtain test1 Tell user what you want, then "read" it in Scanner keyboard = new Scanner(System.in); System.out.print("Enter test one: "); int test1 = keyboard.nextDouble(); Code Demo: Implement the Java Program

22 compile, correct, run, test, compile, correct run, test, correct, run, test, test, test ...
Once the algorithm is translated into a programming language abstraction: use the compiler to generate byte code you will have errors so you'll need to fix errors, compile, and repeat until there are no compile time errors use the Java virtual machine to execute program test the program run the program several times with different sets of input data based on sample problems from analysis compare program output to expected results fix your program if it doesn't work

23 Testing Testing occurs at any point in program development:
Analysis: think of some test cases Design: step through the algorithm Implementation: run program with several sets of input data A running program isn't always right however, testing provides confidence that it works correctly


Download ppt "Chapter 1 Program Development"

Similar presentations


Ads by Google