import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; //FLAW: No comments anywhere. public class DoMany { //FLAW: single letter variable name. Those should only be used in for loops private String f; public DoMany(String fn) { f = fn; } //FLAW: Dave as a method name. Method name should be verbs and should be meaningful //FLAW: The method name has an initial capital letter public void Dave() { try (BufferedReader br = new BufferedReader(new FileReader(f))) { //FLAW: a variable named hungry? int hungry = 1; String line; while (null != (line = br.readLine())) { //FLAW: another single letter variable int i = 0; try { i = Integer.parseInt(line); int j = i / hungry; System.out.println("Result " + j); } // FLAW: Using try catch to catch division by zero catch (ArithmeticException dze) { System.err.println("You divided by zero!!! "); } catch (NumberFormatException nfe) { // FLAW: Catch with nothing in the catch block } hungry = i; } } catch (FileNotFoundException fnf) { // FLAW: out System.out rather than System.err in catch block System.out.println("Could not open ||" + f + "||"); return; } catch (IOException ioe) { System.err.println("Could not read ||" + f + "||"); return; } } public static void main(String[] args) { DoMany mm = new DoMany("data.txt"); mm.Dave(); } }