import java.util.List; import java.util.ArrayList; import java.util.Scanner; public final class Elephant { private static int count = 0; // to generatate unique ids public final int uid, weight, iq; private Elephant (final int i, final int w, final int s) { uid=i; weight=w; iq=s; } // Elephants id numbers are 0, 1, 2, ... public Elephant (final int w, final int s) { this (count++, w, s); } public boolean heavierAndDumberThan (final Elephant e) { return this.weight > e.weight && this.iq < e.iq; } // NB. "public" is necessary. @java.lang.Override public String toString () { return String.format ("%03d [%d,%d]", uid, weight, iq); } /* Equality Note. Every instance of the class 'Elephant' denotes a different elephant. So two elephants are the same iff e1==e2. And since 'equals' is not overriden e1==e2 if 'e1.equals(e1)' (under most conditions). */ public static void main (final String[] args) { final Scanner scan = new Scanner (System.in); // Read in elephants from standard input; add to collection final List<Elephant> list = new ArrayList<Elephant> (); while (scan.hasNextInt()) { list.add (new Elephant (scan.nextInt(), scan.nextInt())); } System.out.println (list); } }