import java.text.NumberFormat;
public class Vehicle implements Comparable< Vehicle >{
private String make;
private String model;
private int year;
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);
}
public int compareToByMake( Vehicle other ){
return make.compareTo( other.make );
}
public int compareTo( Vehicle other ){
if( price < other.price ){
return -1;
}else if( price > other.price){
return 1;
}else{
if( year < other.year ){
return 1;
}else if( year > other.year ){
return -1;
}else{
return 0;
}
}
}
}