I've sent a note with the late policy. 

There's a midterm coming up. 

Wed we have an employer panel. 

What's New? and What's Due? has been updated. 

Try to continue to keep with the reading. 

Next Fri we have no lab (Fall Break). 

The week after we have the midterm. 

I'll post a list of problems to practice. 


C:\Users\dgerman>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman

09/25/2017  09:30 AM    <DIR>          .
09/25/2017  09:30 AM    <DIR>          ..
09/18/2017  10:49 AM               537 .drjava
09/11/2017  10:10 AM    <DIR>          bluej
09/25/2017  09:30 AM    <DIR>          Contacts
09/25/2017  09:41 AM    <DIR>          Desktop
09/25/2017  09:30 AM    <DIR>          Documents
09/25/2017  09:41 AM    <DIR>          Downloads
09/25/2017  09:30 AM    <DIR>          Favorites
09/25/2017  09:30 AM    <DIR>          Links
09/25/2017  09:30 AM    <DIR>          Music
08/29/2017  04:14 AM    <DIR>          OneDrive
09/25/2017  09:30 AM    <DIR>          Pictures
09/25/2017  09:30 AM    <DIR>          Saved Games
09/25/2017  09:30 AM    <DIR>          Searches
09/25/2017  09:30 AM    <DIR>          Videos
               1 File(s)            537 bytes
              15 Dir(s)  363,268,243,456 bytes free

C:\Users\dgerman>cd Desktop

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:41 AM    <DIR>          .
09/25/2017  09:41 AM    <DIR>          ..
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               3 File(s)         27,836 bytes
               2 Dir(s)  363,268,243,456 bytes free

C:\Users\dgerman\Desktop>javac iceblox.gif
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" Iceblox.java
Note: Iceblox.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:45 AM    <DIR>          .
09/25/2017  09:45 AM    <DIR>          ..
09/25/2017  09:45 AM            14,798 Iceblox.class
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               4 File(s)         42,634 bytes
               2 Dir(s)  363,268,087,808 bytes free

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" Iceblox
Error: Main method not found in class Iceblox, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\appletviewer.exe"  iceblox.html
Warning: Can't read AppletViewer properties file: C:\Users\dgerman\.hotjava\properties Using defaults.

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:51 AM    <DIR>          .
09/25/2017  09:51 AM    <DIR>          ..
09/25/2017  09:50 AM             5,917 BeatBox.java
09/25/2017  09:49 AM             8,313 chap13.zip
09/25/2017  09:45 AM            14,798 Iceblox.class
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               6 File(s)         56,864 bytes
               2 Dir(s)  363,264,598,016 bytes free

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" -d . BeatBox.java

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:54 AM    <DIR>          .
09/25/2017  09:54 AM    <DIR>          ..
09/25/2017  09:50 AM             5,917 BeatBox.java
09/25/2017  09:54 AM    <DIR>          chap13
09/25/2017  09:49 AM             8,313 chap13.zip
09/25/2017  09:45 AM            14,798 Iceblox.class
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               6 File(s)         56,864 bytes
               3 Dir(s)  363,264,565,248 bytes free

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:54 AM    <DIR>          .
09/25/2017  09:54 AM    <DIR>          ..
09/25/2017  09:50 AM             5,917 BeatBox.java
09/25/2017  09:54 AM    <DIR>          chap13
09/25/2017  09:49 AM             8,313 chap13.zip
09/25/2017  09:45 AM            14,798 Iceblox.class
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               6 File(s)         56,864 bytes
               3 Dir(s)  363,264,442,368 bytes free

C:\Users\dgerman\Desktop>dir chap13
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop\chap13

09/25/2017  09:54 AM    <DIR>          .
09/25/2017  09:54 AM    <DIR>          ..
09/25/2017  09:54 AM               690 BeatBox$MyDownTempoListener.class
09/25/2017  09:54 AM               523 BeatBox$MyStartListener.class
09/25/2017  09:54 AM               597 BeatBox$MyStopListener.class
09/25/2017  09:54 AM               686 BeatBox$MyUpTempoListener.class
09/25/2017  09:54 AM             5,181 BeatBox.class
               5 File(s)          7,677 bytes
               2 Dir(s)  363,264,442,368 bytes free

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" chap13.BeatBox

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is 129A-3185

 Directory of C:\Users\dgerman\Desktop

09/25/2017  09:59 AM    <DIR>          .
09/25/2017  09:59 AM    <DIR>          ..
09/25/2017  09:50 AM             5,917 BeatBox.java
09/25/2017  09:54 AM    <DIR>          chap13
09/25/2017  09:49 AM             8,313 chap13.zip
09/25/2017  09:59 AM             2,202 ColorFrame.java
09/25/2017  09:59 AM               255 ColorViewer.java
09/25/2017  09:45 AM            14,798 Iceblox.class
09/25/2017  09:41 AM             9,719 iceblox.gif
09/25/2017  09:41 AM               191 iceblox.html
09/25/2017  09:41 AM            17,926 Iceblox.java
               8 File(s)         59,321 bytes
               3 Dir(s)  363,264,528,384 bytes free

C:\Users\dgerman\Desktop>more ColorFrame.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;

public class ColorFrame extends JFrame
{
   private static final int FRAME_WIDTH = 300;
   private static final int FRAME_HEIGHT = 400;

   private JPanel colorPanel;
   private JSlider redSlider;
   private JSlider greenSlider;
   private JSlider blueSlider;

   public ColorFrame()
   {
      colorPanel = new JPanel();

      add(colorPanel, BorderLayout.CENTER);
      createControlPanel();
      setSampleColor();
      setSize(FRAME_WIDTH, FRAME_HEIGHT);
   }

   class ColorListener implements ChangeListener
   {
      public void stateChanged(ChangeEvent event)
      {
         setSampleColor();
      }
   }

   public void createControlPanel()
   {
      ChangeListener listener = new ColorListener();

      redSlider = new JSlider(0, 255, 255);
      redSlider.addChangeListener(listener);

      greenSlider = new JSlider(0, 255, 175);
      greenSlider.addChangeListener(listener);

      blueSlider = new JSlider(0, 255, 175);
      blueSlider.addChangeListener(listener);

      JPanel controlPanel = new JPanel();
      controlPanel.setLayout(new GridLayout(3, 2));

      controlPanel.add(new JLabel("Red"));
      controlPanel.add(redSlider);

      controlPanel.add(new JLabel("Green"));
      controlPanel.add(greenSlider);

      controlPanel.add(new JLabel("Blue"));
      controlPanel.add(blueSlider);

      add(controlPanel, BorderLayout.SOUTH);
   }

   /**
      Reads the slider values and sets the panel to
      the selected color.
   */
   public void setSampleColor()
   {
      // Read slider values

      int red = redSlider.getValue();
      int green = greenSlider.getValue();
      int blue = blueSlider.getValue();

      // Set panel background to selected color

      colorPanel.setBackground(new Color(red, green, blue));
      colorPanel.repaint();
   }
}

C:\Users\dgerman\Desktop>more ColorViewer.java
import javax.swing.JFrame;

public class ColorViewer
{
   public static void main(String[] args)
   {
      JFrame frame = new ColorFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}


C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\javac.exe" ColorViewer.java

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" ColorViewer

C:\Users\dgerman\Desktop>

I showed the programs from the first summary. 

Please try the links in my summaries.

For an array you need to:

  (a) declare it

int[] a;

int a[]; 

  (b) allocate it
  (c) initialize it and use it

The same is true for multidimensional arrays. 

int[][] matrix; 

// int[] matrix[]; 

// int matrix[][]; 

matrix = new int[3][3]; 

for (int row = 0; i < matrix.length; row++)
  System.out.println(java.util.Arrays.toString( matrix[row] ); 

Write a program that creates a random two dimensional array of ints. 

public class Monday {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    int[][] m = new int[size][size]; 
    System.out.println( m ); 
    Monday.show( m ); 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) {
      for (int col = 0; col < a[row].length; col++) {
        System.out.printf("%3d ", a[row][col]);
      }
      System.out.println(); 
    }
  }
}

Here's how this runs: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Monday
java.lang.ArrayIndexOutOfBoundsException: 0
    at Monday.main(Monday.java:3)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:267)
> run Monday 5
[[I@4268a8aa
  0   0   0   0   0 
  0   0   0   0   0 
  0   0   0   0   0 
  0   0   0   0   0 
  0   0   0   0   0 
> run Monday 3
[[I@6fb7163d
  0   0   0 
  0   0   0 
  0   0   0 
> run Monday 9
[[I@5224b047
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 
  0   0   0   0   0   0   0   0   0 


public class Monday {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    int[][] m = new int[size][size]; 
    for (int i = 0; i < m.length; i++) 
      for (int j = 0; j < m[i].length; j++)
        m[i][j] = (int) (Math.random() * 1000);
    System.out.println( m ); 
    Monday.show( m ); 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) {
      for (int col = 0; col < a[row].length; col++) {
        System.out.printf("%3d ", a[row][col]);
      }
      System.out.println(); 
    }
  }
}

Just one change and now we get:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Monday 9
[[I@2840fc52
950 708 870 416 337 221 529 601 477 
440 529 322 362  11 803 875 177 807 
379 682 251 810 561 159 191 183 409 
101   7 874 870 282 296 583 261 633 
343  23 178 181 120 197  84 906 718 
838   2 834 705 260 722 946 279 612 
930 973 836 924 479 704 760 401 775 
247 834 132 950 564 637 756   8 703 
713 662 652 351  83 960 839 758 887 
> run Monday 3
[[I@18e760d8
833 443 597 
544 862 537 
 28 867 552 
> run Monday 3
[[I@94648bd
974 108 961 
637 882 683 
594 671 658 
> run Monday 3
[[I@2844fe8d
 75 955  46 
832 206 361 
869 888 269 
> run Monday 5
[[I@3b508add
529  42 797 711 489 
498 505  75  71 789 
107 203 177 113 745 
400 722 445 559 441 
212 642 157 703 411 
> run Monday 5
[[I@2a66a569
266 143 281 462 396 
228 693  96 889 310 
655 320 385 707 442 
 24 855 412 579 540 
637 859 938  52 719 
>

import java.util.ArrayList; 

public class Tuesday {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    ArrayList<ArrayList<Integer>> matrix; 
    matrix = new ArrayList<ArrayList<Integer>>(); 
    System.out.println( matrix ); 
    for (int i = 0; i < size; i++) {
      ArrayList<Integer> row; 
      row = new ArrayList<Integer>(); 
      for (int j = 0; j < size; j++) {
        row.add( (int) ( Math.random() * 1000 ) );  
      }
      matrix.add(row); 
    }
    System.out.println( matrix ); 
  }
}

This is how this runs:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Tuesday 3
[]
[[343, 169, 757], [898, 121, 773], [787, 628, 602]]
> run Tuesday 5
[]
[[20, 750, 737, 488, 938], [569, 807, 566, 581, 17], [828, 258, 806, 841, 42], [689, 410, 277, 278, 605], [900, 894, 393, 641, 72]]
>

Look at this for Wed:

https://www.cs.indiana.edu/classes/c212-dgerman/fall2015/labNine.html