jgs 00000011 Homework § You won’t submit yet § Draft the source code. It will be discussed in our next lecture Problem to solve: 1. A data structure to store flow charts 2. Nodes? 3. Types? 4. Data / Content? 5. How to connect? 6. Who does the checking? When?
jgs 00000011 The Blob public class Main { public static void main(String[] args) throws Exception { String text; // read text file File file = new File("/Users/Desktop/input.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while ((str = br.readLine()) != null) { text = text + str; System.out.println(str); } // split words Vector tokens = new Vector(); String line; int counterOfLines = 1; do { int eolAt = text.indexOf(/*System.lineSeparator()*/"\n"); if (eolAt >= 0) { line = text.substring(0, eolAt); if (text.length() > 0) text = text.substring(eolAt + 1); } else { line = text; text = ""; } splitLine(counterOfLines, line); counterOfLines++; } while (!text.equals("")); } // token classification int index = 0; char currentChar = ' ‘; String string = ""; if (line.equals("")) return; // etc...
jgs 00000011 Top-Down Stepwise Refinement (step 2) public static String readTextFile (String path) { File file = new File (path); BufferedReader br = new BufferedReader(new FileReader(file)); String str; while ((str = br.readLine()) != null) { text = text + str; } } public static String splitWords (String text) { // code here ... do { int eolAt = text.indexOf("\n"); if (eolAt >= 0) { // code here ... } else { // code here ... } // a lot of code here ! } while (!text.equals("")); } public static void translate (Vector tokens) { // more code ... }
jgs 00000011 Summary § Split the problem in Tasks One method/function do one and only one specific Task § A Tasks enclose Steps (sequences, loops and conditions) Take advantage of recursion
jgs CSE 564 Software Design Javier Gonzalez-Sanchez, Ph.D. [email protected] Fall 2021 Copyright. These slides can only be used as study material for the class CSE564 at ASU. They cannot be distributed or used for another purpose.