public class Player {
  private String name;
  private int points;
  public Player(String name, int points) {
    this.name = name;
    this.points = points;
  }
  public String toString() {
    return this.name + ":" + this.points;  
  }
}

import java.util.*; 

public class Seven {
  public static void main(String[] args) {
    ArrayList<Player> a = new ArrayList<Player>();  
    a.add( new Player("Haleigh", 18) );     
    a.add( new Player("Gerry"  , 19) ); 
    a.add( new Player("Frank"  , 20) );      
    a.add( new Player("Ethan"  , 21) ); 
    a.add( new Player("David"  , 22) );     
    a.add( new Player("Chris"  , 23) ); 
    a.add( new Player("Brian"  , 24) );     
    a.add( new Player("Alex"   , 25) ); 
    System.out.println( a ); 
  }
}

Assume somebody gives you two players: a, b. Find out if: 

  (a) a should be ahead of b      (-1) 
  (b) b should be ahead of a      ( 1)
  (c) a and b are OK in any order ( 0)  

Scores <= 21 should come first in the list. Among these higher scores 
come first. Within the second category the smaller scores come first. 
When scores are the same I'd like players to be sorted alphabetically.


Yongtao, Alex D., Seth W., Jeremy B, Thomas A, Steve B, Clayton T, 
Daniel O, Noah P, Jake diBella, Hao T, Angely, Josh P, Jay K, Nick F, 
Xinning W, Pong C, Maro R, Andrew D, Anna McN, Jacob C, Taylor P, Samy R, 
Jiachen, Rishu, Santiago, Kellen, Ryan P, Biao Z, Josh M, Anthony C,
Adam K, Dimas M, Omar, Austin M, Brittany H, Joel P, Donovan M, Zhengyu L, 
Shichao, Laura H, Dustin K, Sam Berron, Jordan L, David L, Tian J, Sam McKay, 
Yingzhenm Troy, Bokai, Ethan Y, Morgan N, Creighton H, Scott M, Megan H,
Nikita H, Brad V, Quentin L, Sean P, Joey R, cc56, Will T., Dhruv*

public class Player {
  private String name;
  private int points;
  public Player(String name, int points) {
    this.name = name;
    this.points = points;
  }
  public String toString() {
    return this.name + ":" + this.points;  
  }
  public int getPoints() {
    return this.points;  
  }
  public String getName() {
    return this.name;  
  }
}

import java.util.*; 

public class Seven {
  public static void main(String[] args) {
    ArrayList<Player> a = new ArrayList<Player>();  
    a.add( new Player("Howard", 18) ); 
    a.add( new Player("Haleigh", 18) ); 
    a.add( new Player("Gerry"  , 19) ); 
    a.add( new Player("Frank"  , 25) ); 
    a.add( new Player("Andrew" , 20) );     
    a.add( new Player("Ethan"  , 21) ); 
    a.add( new Player("David"  , 22) ); 
    a.add( new Player("Chris"  , 23) ); 
    a.add( new Player("Brian"  , 24) ); 
    a.add( new Player("Alex"   , 20) ); 
    System.out.println( a ); 
    Collections.sort(a, new Judge() ); 
    System.out.println( a ); 
  }
}
import java.util.*; 

public class Judge implements Comparator<Player> {
  public int compare(Player a, Player b) {
    if ( a.getPoints() <= 21 && b.getPoints() > 21 ) return -1;
    else if ( a.getPoints() > 21 && b.getPoints() <= 21) return 1; 
    else if ( a.getPoints() <= 21 && b.getPoints() <= 21) {
      if (a.getPoints() > b.getPoints()) return -1; 
      else if (a.getPoints() < b.getPoints()) return 1;
      else return a.getName().compareTo(b.getName());
    } else { // both bigger 
      if (a.getPoints() > b.getPoints()) return 1; 
      else if (a.getPoints() < b.getPoints()) return -1;
      else return a.getName().compareTo(b.getName());
    }
  }
}

Now let's come up with something for #6

import java.awt.event.*; 

public class Helper implements ActionListener {
  int i = 0; 
  public void actionPerformed(ActionEvent e) {
    this.i = this.i + 1; 
    System.out.println( i );  
  }
}

import javax.swing.*; 

public class Six {
  public static void main(String[] args) {
    Timer t = new Timer(1500, new Helper()); 
    t.start(); 
  }
}

Now a different way of processing mouse events (the listener is separate)

import javax.swing.*; 

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

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

public class Two extends JComponent {
  int x, y; 
  public Two() {
    this.addMouseMotionListener( new Helper(this) );  
  }
  public void paintComponent(Graphics g) {
    g.drawString("(" + this.x + ", " + this.y + ")", this.x, this.y); 
  }
  
}

import java.awt.event.*; 

public class Helper implements MouseMotionListener {
  Two two; 
  Helper(Two two) {
    this.two = two;  
  }
  public void mouseDragged(MouseEvent e) {
    
  }
  public void mouseMoved(MouseEvent e) {
    this.two.x = e.getX(); 
    this.two.y = e.getY(); 
    this.two.repaint(); 
  }  
}

--