Howdy. 

Seating. 

Office hours. 

Still due (today): Lab 05. 

Next exam will have a part that will give you a chance to redo this first exam. 

You can also retake any exam any number of times with me just not at the very end. 

Report if well done will bring your grade up. First exams scores: low. 

We have a goal, we better keep it in sight. 

https://www.cs.indiana.edu/classes/c212-dgerman/fall2016/resources/koobtxet.pdf

(require 2htdp/image)
(require 2htdp/universe)

; A Point is a (make-point Number Number)
(define-struct point (x y))

; A Circle is a (make-circl Point Number)
(define-struct circl (center radius))

; A ManyCircl is one of:
;   -- empty

;   -- (cons Circle ManyCircl)

; A World is a ManyCircl 

; (big-bang initial
;           (to-draw ...)
;           (on-tick ...)
;           (on-mouse ...))

(define initial empty)

; render : World -> Image
; (define (render world)
;   (cond ((empty? world) ...)
;         (else (... (first world) ... (render (rest world)) ...))))
(define (render world)
  (cond ((empty? world) (empty-scene 400 400))
        (else (place-image (circle (circl-radius (first world)) "outline" "red")
                           (point-x (circl-center (first world)))
                           (point-y (circl-center (first world)))
                           (render (rest world))))))

(define sample-world (cons (make-circl (make-point 300 300) 30) 
                      (cons (make-circl (make-point 200 100) 80)
                       (cons (make-circl (make-point  50  50) 10) empty))))

; enlarge : circl -> circl
; increases the radius by 1 pixel 
(define (enlarge circl)
  (make-circl (circl-center circl) (add1 (circl-radius circl))))

; update : world -> world

(define (update world)
  (cond ((empty? world) world)
        (else (cons (enlarge (first world))
                    (update (rest world))))))

; meh : world x y event -> world

(define (meh world x y event)
  (cond ((mouse=? "button-down" event) 
         (cons (make-circl (make-point x y) 1)
               world))
        (else world)))

(big-bang sample-world
          (to-draw render)
          (on-tick update)
          (on-mouse meh))

Bunch of coins. 

Structural recursion. 

Design recipe. 

How do we write our own Big Bang in Java.

How can you implement Ripples? 

Need to 

  (a) draw 

  (b) process events (mouse, keyboard)

  (c) use timers (keep track of time)

  (d) pass an initial world to big-bang 

How about the structure of the world in Ripples? 

Arrays and ArrayLists. 

https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/me.pdf

Next exam:

(a) short answer questions

(b) one or two programs from a pool of programs 

I will post them this week. 

Each exam will be individual with picture and your own random selection.

What if I need to remember and report (perhaps sort) all data entered.

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> int[] a;
> int b[];
> b = new int[6]
{ 0, 0, 0, 0, 0, 0 }
> b[2] = 4
4
> b[0] = -2
-2
> b[b.length - 1] = 7
7
> b
{ -2, 0, 4, 0, 0, 7 }
> b[1] = 6
6
> b[3] = -1
-1
> b[4] = 12
12
> b
{ -2, 6, 4, -1, 12, 7 }
> int[] c = new int[b.length + 1]
> c
{ 0, 0, 0, 0, 0, 0, 0 }
> b
{ -2, 6, 4, -1, 12, 7 }
> c[c.length - 1] = 1
1
> c
{ 0, 0, 0, 0, 0, 0, 1 }
> for (int i = 0; i < b.length; i++) c[i] = b[i];
> c
{ -2, 6, 4, -1, 12, 7, 1 }
> b
{ -2, 6, 4, -1, 12, 7 }
> b
{ -2, 6, 4, -1, 12, 7 }
> c
{ -2, 6, 4, -1, 12, 7, 1 }
> b = c
{ -2, 6, 4, -1, 12, 7, 1 }
> b
{ -2, 6, 4, -1, 12, 7, 1 }
> int n = 3
> n = n + 1
4


Here's a subtle point:

Welcome to DrJava.  Working directory is C:\Users\soicloan\Desktop
> int[] n = new int[2];
> n
{ 0, 0 }
> int[] m = new int[1]
> m
{ 0 }
> int[] q = new int[0]
> q
{  }


Here's the program now:

import java.util.Arrays; 
import java.util.Scanner; 

public class One {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);      
    System.out.print("Number: "); 
    int[] numbers = new int[0]; 
    String line = in.nextLine(); 
    while (! line.equals("bye")) {
      int number = Integer.parseInt(line); 
      numbers = Arrays.copyOf( numbers , numbers.length + 1 ); 
      numbers[numbers.length - 1] = number; 
      System.out.println( Arrays.toString( numbers ) );
      System.out.print("Number: "); 
      line = in.nextLine(); 
    }
    System.out.println( Arrays.toString( numbers )); 
  }
}

Questions: 

  (a) how do we sort

  (b) can we define our own copyOf? 

Here's my definition: 

import java.util.Arrays; 
import java.util.Scanner; 

public class One {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);      
    System.out.print("Number: "); 
    int[] numbers = new int[0]; 
    String line = in.nextLine(); 
    while (! line.equals("bye")) {
      int number = Integer.parseInt(line); 
      numbers = Arrays.copyOf( numbers , numbers.length + 1 ); 
      numbers[numbers.length - 1] = number; 
      System.out.println( Arrays.toString( numbers ) );
      System.out.print("Number: "); 
      line = in.nextLine(); 
    }
    System.out.println( Arrays.toString( numbers )); 
    Arrays.sort( numbers ); 
    System.out.println( Arrays.toString( numbers )); 
  }
}

That's just a small enhancement.

Now the code: