Preference       
 ************* MVC web app 
        ****** Game engine with game(s)

Problems                            Votes Average
                                      0            1 MouseMotionListener   
                          2           1     2      2 MouseListener
          3                           1     3      3 Keeping Time
1 2 1       3       3   3   1 1 1     9     1.77   4 Comparable
2 1   3 3 2     3       1 3 2 1 3    11     2.18   5 Comparator
      2       3   3 2 1 2   3 2       8     2.25   6 Exceptions
            1   2   1                 3     1.33   7 Key events
3 3 2 1 1 1     1 1       1     2    10     1.6    8 Graphics
  3     2   2     2   2       3       6     2.33   9 Simple GUIs

Topics to discuss in lab:

  Sorting 
  Exceptions
  Graphics 
--
  GUIs

Misato, Khalea, Tao, Rafael, Jillian, Kefei, Iris, Garrett, Yibo, John, 
Daniel C, Nicholas, Noah, Keiland, Santiago, Jiang, Bihan, Justin, Ryan, 
Taylor, Elise, Stuart, Daniel R

import java.util.*; 

public class Student implements Comparable<Student> {
  private String name;
  private int age; 
  private double gpa;
  public int getAge() {
    return this.age;  
  }
  public Student(String name, int age, double gpa) {
    this.name = name; 
    this.age = age;
    this.gpa = gpa; 
  }
  public int compareTo(Student other) {
    if (this.gpa > other.gpa) return -1; // in front of other
    else if (this.gpa < other.gpa) return 1; 
    else return this.name.compareTo(other.name); // lexicographic when same gpa 
  }
  public String toString() {
    return this.name + "(" + this.age + "/" + this.gpa + ")"; 
  }
}

--

import java.util.*; 

class Example {
  public static void main(String[] args) {
    ArrayList<Student> a = new ArrayList<Student>(); 
    a.add(new Student("Larry" , 12, 1.40));
    a.add(new Student("Leslie", 11, 2.20));
    a.add(new Student("Laura" , 10, 2.20));
    a.add(new Student("Lyndon",  9, 3.10));
    a.add(new Student("Lynn"  ,  9, 3.22));
    a.add(new Student("Lee"   ,  8, 3.23));
    a.add(new Student("Lance" ,  8, 3.21));
    System.out.println( a ); 
    Collections.sort( a ); 
    System.out.println( a );     
    Collections.sort( a, new AscendingByAge() ); 
    System.out.println( a );         
  }
}

--

import java.util.*; 

public class AscendingByAge implements Comparator<Student> {
  public int compare(Student a, Student b) {
    if (a.getAge() > b.getAge()) return 1; 
    else if (a.getAge() < b.getAge()) return -1; // a in front of b
    else return 0; 
  }
}

--

public class Nothing {
  public static void main(String[] args) {
    System.out.println( args.length );  
    if (args.length == 1) {
      try { 
        int a = Integer.parseInt( args[0] );       
        System.out.println( Math.sqrt( a ) );
      } catch (Exception a) {
        System.out.println( "Shame on you: " + a );  
      }
    }
  }
}

--

import java.util.Scanner; 

public class Six {
  public static void main(String[] args) {
    while (true) { 
      System.out.print("Please enter an integer: "); 
      Scanner s = new Scanner(System.in); 
      String n = s.nextLine();
      try {
        int number = Integer.parseInt(n); 
        System.out.println("You have entered " + n + " with square root " + Math.sqrt(number));
        s.close();
        break;
      } catch (Exception e) {
        System.out.println("Sorry, " + n + " not an integer."); 
      }
    }
  }
}

--

import javax.swing.*; 

public class Justin {
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    a.getContentPane().add( new Projector(16) ); 
    a.setVisible(true); 
    a.setSize(400, 400); 
  }
}

import java.awt.*; 

public class Circle {
  int x, y, radius;
  Color c;
  public Circle(int x, int y, int r, Color c) {
    this.x = x; 
    this.y = y;
    this.radius = r;
    this.c = c;
  }
  public void draw(Graphics g) {
    g.setColor(this.c);
    g.fillOval(this.x - this.radius, 
               this.y - this.radius,     
               2 * this.radius,
               2 * this.radius);
    g.setColor( Color.BLACK ); 
    g.drawOval(this.x - this.radius, 
               this.y - this.radius,     
               2 * this.radius,
               2 * this.radius);
    

  }
}

import javax.swing.*; 
import java.awt.*;
import java.util.*;

public class Projector extends JComponent {

  ArrayList<Circle> circles = new ArrayList<Circle>(); 
  
  public Projector(int circles) {
    for (int i = 0; i < circles; i++) {
      this.circles.add( new Circle( (int) (Math.random() * 200 + 100) , 
                                    (int) (Math.random() * 200 + 100), 
                                    (int) (Math.random() *  20 +  10), 
                                    new Color( (int) (Math.random() * 128 + 128), 
                                               (int) (Math.random() * 128 + 128), 
                                               (int) (Math.random() * 128 + 128) 
                                             ) ) );  
    }
  }
  int count; // = 0; 
  public void paintComponent(Graphics g) {
     this.count += 1;
     System.out.println( this.count ); 
    for (Circle c : this.circles)
      c.draw(g); 
  }
}

--