Review for CSCI 1380.03 (Java) Chapter six: The BasicMenu class Arrays: String theOptions[]; String infor; int i; theOptions = new String[4]; infor = new String(30); for (i = 0; i < 4; i ++) { infor = in.readLine(); theOptions[i] = new String(infor); } Iterations: For loop: for (initial; loop condition; update) statement; Random g = new Random(); for (i = 0; i < 100; i ++) System.out.println(g.nextInt()); While loop: while (condition) statement; i = 0; while (i < 100) { System.out.println(g.nextInt()); i ++; } Typically, the statement inside a while loop always has to have some action that modifies the condition, otherwise, it would be an infinite loop Basic keyboard input: Declare a keyboard input stream DataInputStream key = new DataInputStream( System.in ); Use of try/catch cluase try { str = in.readLine(); } catch ( IOException e) { System.out.println("I/O exception"); } Read integers and doubles: // read an integer try { str = in.readLine(); // str is a String n = Integer.parseInt(str); // n is an integer valid = true; } catch (NumberFormatException e) { System.out.println("Number format invalid, try again"); } catch (IOException e) { Sytem.out.println("I/O error, exiting"); System.exit(1); } // read a double try { str = in.readLine(); // str is a String r = Double.valueOf(str); // r is a Double valid = true; } catch (NumberFormatException e) { System.out.println("Number format invalid, try again"); } catch (IOException e) { Sytem.out.println("I/O error, exiting"); System.exit(1); } Chapter seven: The AdaptingMenu class The switch statement switch ( value ) { case 4 : System.out.println("perfect"); break; case 3 : System.out.println("perfect"); break; case 2 : System.out.println("fair"); break; default: System.out.println("try again"); } // End switch Menu driven program Chapter eight: concurrent processes concept of threads danger of inconsistant data synchronized thread model: sleep(), suspend(), resume(); syntax: class name extends Thread { // other methods and members void run () { // required for a thread } }