package demo_35;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TryCar {

	public static void main(String[] args) {
		List<Car> cars = new ArrayList<Car>(); // Top five cars
		cars.add(new Car("Aston Martin","DB5",1964,new FullName("James","","Bond")));
		cars.add(new Car("George Barris","BatMobile", 1963,new FullName("Bruce","","Wayne")));
		cars.add(new Car("Rolls Royce","Phantom V",1965,new FullName("John","Winston","Lennon")));
		cars.add(new Car("Mercedes Benz","300SL Gullwing",1955,new FullName("Clark","","Gable")));
		cars.add(new Car("Deusenberg","Model J",1931,new FullName("Phil","","Berg")));
		
		System.out.println("Top Five Cars:");
		printCars(cars);
		
		// Sort by date (extend Comparable)
		Collections.sort(cars);
		System.out.println("\nCars by year...");
		printCars(cars);
		
		// Sort by Make (make a new class that implements Comparator)
		Collections.sort(cars,new CompareCarMake());
		System.out.println("\nCars by make...");
		printCars(cars);
		
		//Sort by Owner
		Collections.sort(cars,(a,b)->a.owner.last.compareTo(b.owner.last));
		System.out.println("\nCars by owner...");
		printCars(cars);
		
				
	}
	
	private static void printCars(List<Car> cars) {
		for(int i=0;i<cars.size();i++) {
			System.out.println("" + i + " : " + cars.get(i));			
		}
	}

}

