Chapter 1 Writing a Program Describe process models

Chapter 1: Writing a Program Describe process models of software life cycle and discuss their phases, advantages and disadvantages. Prof. Alcides Alvear

Objectives • Analyze issues for simple programs – Requirements – Design Constraints – Testing – Error Estimation – Implementation details • Understand sequence of activities • Preview of future topics

Requirements • Requirements – define and qualify system – Defined by client, with help from engineer – Functional – define what must be done – Non-Functional – qualify the functional ones • Design constraints – On design or implementation – Programming language, platforms etc

A Simple Problem (Asignación) • Suponga que tiene un file que contiene un grupo de líneas de texto. – Diseñe un algoritmo que: • Lea y cuente un patrón específico del file. • lea y muestre una línea específica del file. • Ordene alfabeticamente el file (ascendente) "Manos a la obra"

Functional requirements • Input format – Character size – Line separator • Specify Sorting – Numbers – Upper/lowercase • Special cases: – ? ? Spanish, English, numbers, etc. • Boundaries – empty line, empty file • Error Conditions – Actions? ? ?

Nonfunctional requirements • Performance – Important? ? , is an issue – In this case. Performance=1 min, 100 lines of 100 ch. • Real-time ? – Performance is an issue – Quick sort, expected running time=? , (better, bad) – You have real-time requirements • Heap Sort or Merge Sort? ? • Modifiability – Life expectancy of the program • Only once or very, very years

Design Constraints • User Interface – GUI, CLI, Web … • Typical input and size • Platforms • Schedule

Design Decisions • Programming Languages • Algorithms

Testing • Acceptance testing – if it fails, client rejects program • Unit testing – by programmer, on each piece • Black-Box – assume no knowledge of code • White-Box – test the code as written

Estimating • How much effort is required ? • Cost • Time / Scheduling

Implementation Rules • • • Be consistent Choose names carefully Test before using Know thy libraries Do code reviews

Basic Design • Class String. Sorter – Read – Sort – Write – Wrapper to do Read then Sort then Write • Will unit-test each method • Will use Array. List to hold the lines

Review • • • Objectives Requirements Functional Requirements Nonfunctional Requirements Design Constraints Design Decisions Testing Estimating Implements Rules Basic Design Lectures recommended: – PA-chapter 01. ppt; – 0273710133_pp 01 v 2. ppt

• Do it

Fases genéricas Definición Desarrollo Mantenimiento

Definición 1. 1. Ing. De Computadoras. 1. 2. Planificación de proyectos. 1. 3. Análisis de requisitos.

Desarrollo 2. Desarrollo. 2. 1. Diseño de software. 2. 2. Programación (generación de códigos) 2. 3. Prueba y evaluación de sistemas.

Mantenimiento 3. Mantenimiento. 3. 1. Corrección. 3. 2. Adaptación. 3. 3. Mejora. 3. 4. Prevención.

Actividades protectoras Marco de trabajo común Actividades: - Tareas - Entregas - Hitos - Puntos SQA Actividades protectoras

Actividades protectoras • • Seguimiento y control del proyecto de software. Revisiones técnicas formales. Garantía de la calidad del software. Gestión de configuración del software. Preparación y producción de documentos. Gestión de Reutilización. Mediciones. Gestión de Riesgos.

Referencias • http: //ingenieriasoftbejarano. blogspot. com/2012/10/caracteristicas-ytipos-de-software. html

Implement import java. io. *; // for Reader(s), Writer(s), IOException import java. util. *; // for List, Array. List, Iterator public class String. Sorter { Array. List lines; public void read. From. Stream(Reader r) throws IOException { Buffered. Reader br=new Buffered. Reader(r); lines=new Array. List(); while(true) { String input=br. read. Line(); if(input==null) break; lines. add(input); } }

Test public class Test. String. Sorter extends Test. Case { private Array. List make 123() { Array. List l = new Array. List(); l. add("one"); l. add("two"); l. add("three"); return l; } public void test. Read. From. Stream() throws IOException{ Reader in=new File. Reader("in. txt"); String. Sorter ss=new String. Sorter(); Array. List l= make 123(); ss. read. From. Stream(in); assert. Equals(l, ss. lines); }

Figure 1. 5: Junit GUI

Implement static void swap(List l, int i 1, int i 2) { Object tmp=l. get(i 1); l. set(i 1, l. get(i 2)); l. set(i 2, tmp); }

Test public void test. Swap() { Array. List l 1= make 123(); Array. List l 2=new Array. List(); l 2. add("one"); l 2. add("three"); l 2. add("two"); String. Sorter. swap(l 1, 1, 2); assert. Equals(l 1, l 2); }

Implement static int find. Idx. Biggest(List l, int from, int to) { String biggest=(String) l. get(0); int idx. Biggest=from; for(int i=from+1; i<=to; ++i) { if(biggest. compare. To(l. get(i))<0) {// it is bigger biggest=(String)l. get(i); idx. Biggest=i; } } return idx. Biggest; } Figure 1. 8: find. Idx. Biggest method

Test public void test. Find. Idx. Biggest() { String. Sorter ss=new String. Sorter(); Array. List l = make 123(); int i=String. Sorter. find. Idx. Biggest(l, 0, l. size()1); assert. Equals(i, 1); } Figure 1. 9: test. Find. Idx. Biggest method

Implement public void sort() { for(int i=lines. size()-1; i>0; --i) { int big=find. Idx. Biggest(lines, 0, i); swap(lines, i, big); } } Figure 1. 10: sort method

Test public void test. Sort 1() { String. Sorter ss= new String. Sorter(); ss. lines=make 123(); Array. List l 2=new Array. List(); l 2. add("one"); l 2. add("three"); l 2. add("two"); ss. sort(); assert. Equals(l 2, ss. lines); } Figure 1. 11 test. Sort 1 method

Know try library void sort() { java. util. Collections. sort(lines); } A sort routine already exists in java (and most other languages)

Implement public void write. To. Stream(Writer w) throws IOException { Print. Writer pw=new Print. Writer(w); Iterator i=lines. iterator(); while(i. has. Next()) { pw. println((String)(i. next())); } } Figure 1. 13: write. To. Stream method

Test public void test. Write. To. Stream() throws IOException{ // write out a known value String. Sorter ss 1=new String. Sorter(); ss 1. lines=make 123(); Writer out=new File. Writer("test. out"); ss 1. write. To. Stream(out); out. close(); // then read it and compare Reader in=new File. Reader("in. txt"); String. Sorter ss 2=new String. Sorter(); ss 2. read. From. Stream(in); assert. Equals(ss 1. lines, ss 2. lines); }

Implement public void sort(String input. File. Name, String output. File. Name) throws IOException { Reader in=new File. Reader(input. File. Name); Writer out=new File. Writer(output. File. Name); String. Sorter ss=new String. Sorter(); ss. read. From. Stream(in); ss. sort(); ss. write. To. Stream(out); in. close(); out. close(); }

Test public void test. Sort 2() throws IOException { // write out a known value String. Sorter ss 1=new String. Sorter(); ss 1. sort("in. txt", "test 2. out"); Array. List l=new Array. List(); l. add("one"); l. add("three"); l. add("two"); // then read it and compare Reader in=new File. Reader("test 2. out"); String. Sorter ss 2=new String. Sorter(); ss 2. read. From. Stream(in); assert. Equals(l, ss 2. lines); } Figure 1. 16: test. Sort 2 method

Command-Line interface import java. io. IOException; public class String. Sorter. Command. Line { public static void main(String args[]) throws IOException { if(args. length!=2) { System. out. println("Use: cmd inputfile outputfile"); } else { String. Sorter ss=new String. Sorter(); ss. sort(args[0], args[1]); } } }

A Bad GUI public class String. Sorter. Bad. GUI { public static void main(String args[]) throws IOException { try { String. Sorter ss=new String. Sorter(); String in. File. Name=JOption. Pane. show. Input. Dialog ("Please enter input file name"); String out. File. Name=JOption. Pane. show. Input. Dialog ("Please enter output file name"); ss. sort(in. File. Name, out. File. Name); } finally { System. exit(1); } }

A Better GUI Click any button, to get the open dialog
- Slides: 38