001package algs25;
002import stdlib.*;
003/* ***********************************************************************
004 *  Compilation:  javac Job.java
005 *  Execution:    java Job
006
007 *  A data type that implements a processing job.
008 *
009 *
010 *************************************************************************/
011
012public class XJob implements Comparable<XJob> {
013        private final String name;
014        private final double time;
015
016        public XJob(String name, double time) {
017                if (time < 0) throw new Error("Can't have negative processing time");
018                this.name = name;
019                this.time = time;
020        }
021
022        public double time() { return time; }
023
024        public int compareTo(XJob that) {
025                if      (this.time < that.time) return -1;
026                else if (this.time > that.time) return +1;
027                else return 0;
028        }
029
030        public String toString() {
031                return String.format("%s %.1f", name, time);
032        }
033
034        public static void main(String[] args) {
035                int N = Integer.parseInt(args[0]);
036                StdOut.println(N);
037                for (int i = 0; i < N; i++) {
038                        double time = StdRandom.uniform(1000);
039                        XJob job = new XJob("JOB" + i, time);
040                        StdOut.println(job);
041                }
042        }
043
044}