/home/caleb/ASDV-Java/Semester 2/Exams/Exam2-Practice_CalebFontenot/src/main/java/com/calebfontenot/exam2/practice_calebfontenot/Dealership.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.exam2.practice_calebfontenot;

import java.util.ArrayList;
import java.util.Arrays;

/**
 *
 * @author caleb
 */
public class Dealership extends ArrayList<Automobile> {
    /** Sorts the inherited ArrayList of Automobiles
     *   into ascending order by vin number.
     * @param d the Dealership of Automobiles
     */
    public static void sortByVin(Dealership d) { //java.util.Collections.sort() could do all of this in a single line
        Object[] dealershipArray = d.toArray();
        Arrays.sort(dealershipArray);
        d.clear();
        for (int i = 0; i < dealershipArray.length; ++i) {
            d.add((Automobile) dealershipArray[i]);
        }
    }
    public static void main(String[] args)
    {
        Dealership d = new Dealership();
        
        d.add(new Automobile("8", new CountryOfOrigin("USA".toCharArray())));
        d.add(new Automobile("1", new CountryOfOrigin("GERMANY".toCharArray())));
        System.out.println("THE ORIGINAL DEALERSHIP\n" + d);
        Dealership.sortByVin(d);
        System.out.println("\nTHE SORTED BY VIN DEALERSHIP\n" + d);
    }
}