import java.text.NumberFormat;

public class Vehicle implements Comparable< Vehicle >{

    private String make;
    private String model;
    private int year;    // YYYY
    private double price;

    public Vehicle( ){
        make = "?";
        model = "?";
        year = 0;
        price = 0.0;
    }

    public Vehicle( String make, String model, int year, double price ){
        this.make = make;
        this.model = model;
        this.year = year;
        this.price = price;
    }

    public void setMake( String make ){    this.make = make; }
    public void setModel( String model ){  this.model = model; }
    public void setYear( int year ){       this.year = year; }
    public void setPrice( double price ){   this.price = price; }

    public String getMake(){   return make; }
    public String getModel(){  return model; }
    public int getYear(){      return year; }
    public double getPrice(){  return price; }

    public String toString(){
        return year + " " + make + " " + model + ": " + NumberFormat.getCurrencyInstance().format(price);
    }

    // sort by make
    public int compareToByMake( Vehicle other ){
        /* 
        if(make.equals(other.make)){
            return 0;
        }else if( make.compareTo( other ) < 0){
            return -1;
        }else{
            return 1;
        }
        */
        return make.compareTo( other.make );
    }

    // sort by price then year
    public int compareTo( Vehicle other ){

        if( price < other.price ){
            return -1;
        }else if( price > other.price){
            return 1;
        }else{ // same price
            //return (year - other.year) * -1;
            if( year < other.year ){
                // this car is older than the other
                return 1; // but it later in a sorted list
            }else if( year > other.year ){
                return -1;
            }else{
                return 0;
            }
        }
    }
}