/** * Car object. * * @author Sean Handley, 320097@swan.ac.uk * @version May 2007 */ public class Car implements Comparable<Car>{ protected double weight; protected String registration; protected String manufacturer; /** * * Constructor for Car. * * @param weight * @param manufacturer * @param registration */ public Car(double weight, String manufacturer, String registration) { this.weight = weight; this.registration = registration; this.manufacturer = manufacturer; } /** * Compare this car to another. * * Implemented method specified in comparable interface. */ public int compareTo(Car that) { if(this.weight > that.weight) { return 1; } else if(this.weight == that.weight) { return 0; } else { return -1; } } /** * Print out fields of this Car. * * Overrides the toString method in Object. */ public String toString() { return "[" + weight + ", " + registration + ", " + manufacturer + "]"; } }