From: German, Dan-Adrian
Sent: Monday, September 25, 2017 9:21 AM
To: [...]
Cc: d.adr.german@gmail.com
Subject: late policy (reminder)
 
I have been asked to re-state the late policy so here it is: 

1. In this class you get graded for (a) attendance, (b) labs, (c) homework, (d) exams and (e) semester project.

2. If something is incorrectly graded contact your grader and get that fixed within one or two weeks. 

3. If you forgot to submit, or submitted low quality work (this includes exams) you are welcome to make up.

4. Make ups are in accordance with the following rules: 

  (a) anything can be made up any number of times (but see below, makeups are very time consuming)
  (b) make ups are with dgerman only and in LH204 
  (c) make appointment via http://silo.cs.indiana.edu:8346/cgi-bin/fall2017/schedule
  (d) make sure there is enough time to defend and get a grade when you make an appointment
  (e) you can't leave the make up without a grade in the gradebook or it else doesn't count
  (f) make sure there are no more than 4 people in the office when you schedule your make up; 
  (f') if there are more than 4 (four) people in LH204 I can lock the door, close and leave 
  (g) in general you can make up one thing per day and person only (tho exceptions sometimes can be made)
  (h) you need to study before making a test up, don't just come here to make up hoping to get lucky
  (i) submit the code for the lab or homework to dgerman via Canvas before coming to LH204 for a makeup

5. If you have any questions or any of what I wrote above is unclear please let me know (dgerman@indiana.edu). 

Sincerely,
Adrian German

--

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

Arrays:

  int[] a; // declaration

  // int a[]; 

  a = new int[6]; // allocation

  a[1] = 5; // initialization 

  This is an example of a uni-dimensional array. 

Two-dimensional arrays (matrices):

  int[][] m; // declaration

  // int[] m[]; 

  // int m[][]; 

  m = new int[3][3]; 

  m[0][1] = 9; // like in the magic square in the notes

public class Magic {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    int[][] m = new int[size][size]; 
    System.out.println( m ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java Magic 5
[[I@4d719374
> java Magic 3
[[I@2c7ceb69
> java Magic 7
[[I@55535d18


public class Magic {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    int[][] m = new int[size][size]; 
    System.out.println( m ); 
    Magic.show( m ); 
    for (int i = 0; i < m.length; i++) {
      for (int j = 0; j < m[i].length; j++) {
        m[i][j] = (int) (Math.random() * 10); 
      }
    }
    Magic.show( m ); 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) {
      System.out.println( java.util.Arrays.toString( a[row] ) );  
    }
    System.out.println("--------------------"); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Magic
java.lang.ArrayIndexOutOfBoundsException: 0
    at Magic.main(Magic.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 Magic 5
[[I@179808e
[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]
--------------------
[6, 4, 4, 4, 3]
[1, 2, 7, 2, 8]
[8, 5, 5, 0, 8]
[8, 5, 9, 3, 8]
[8, 4, 5, 3, 0]
--------------------
> run Magic 3
[[I@32149f90
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
--------------------
[1, 5, 8]
[0, 8, 2]
[0, 5, 3]
--------------------
> run Magic 7
[[I@463bd845
[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, 4, 9, 2, 3, 6, 5]
[0, 1, 5, 5, 8, 0, 8]
[1, 0, 3, 8, 5, 2, 1]
[5, 0, 6, 8, 9, 7, 9]
[3, 5, 1, 0, 0, 4, 9]
[3, 0, 4, 9, 0, 6, 0]
[9, 5, 6, 1, 2, 3, 0]
--------------------


import java.util.ArrayList; 

public class Something {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    // int[] a;
    ArrayList<ArrayList<Integer>> a; 
    a = new ArrayList<ArrayList<Integer>>(); 
    System.out.println( a ); 
    for (int i = 0; i < size; i++) {
      ArrayList<Integer> row = new ArrayList<Integer>(); 
      a.add( row ); 
    }
    System.out.println( a ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java Something 8
[]
[[], [], [], [], [], [], [], []]
> java Something 3
[]
[[], [], []]
> java Something 5
[]
[[], [], [], [], []]


import java.util.ArrayList; 

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

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java Something 3
[]
[[0, 0, 9], [5, 4, 1], [1, 1, 7]]
> java Something 5
[]
[[8, 6, 7, 9, 0], [5, 8, 4, 5, 3], [8, 0, 5, 3, 5], [9, 6, 1, 8, 4], [5, 8, 5, 5, 2]]
> java Something 4
[]
[[5, 9, 3, 6], [1, 2, 5, 4], [3, 1, 8, 6], [8, 3, 5, 9]]


Minute paper: 

Please write down the code for java.util.Arrays.sort(int[] n)

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

import java.util.Arrays;

public class Minute {
  public static void main(String[] args) {
    int[] a = new int[args.length]; 
    for (int i = 0; i < a.length; i++) 
      a[i] = Integer.parseInt( args[i] ); 
    System.out.println(Arrays.toString( a )); 
    Minute.sort( a );
    System.out.println(Arrays.toString( a )); 
  }
  public static void sort(int[] a) {
    // your code here not what you see below
    java.util.Arrays.sort( a ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java Minute 4 2 3 5 1 6 3
[4, 2, 3, 5, 1, 6, 3]
[1, 2, 3, 3, 4, 5, 6]
> java Minute 5 5 2 2 3 1 1 4 3 5 4 2 1
[5, 5, 2, 2, 3, 1, 1, 4, 3, 5, 4, 2, 1]
[1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 5]


--

maxxmill nick and matt npfaro@indiana.edu mrlonis@indiana.edu

ccontos grace hopper 10/03 10/05 excused