/*
 * @topic T02205 Sorting Comparable Objects
 * @brief Array of products, foreach loop, Arrays.sort( ) demo 
*/
package arraydemo;

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        // Create and populate array of products:
        Product[] products = {
            new Product(40, "Widget", 30.50),
            new Product(10, "Gadget", 40.50),
            new Product(99, "Knob", 10.50)
        };

        // Print product descriptions
        for (Product prod : products) {
            System.out.println(prod.getDescription());
        }

        // Sort array of products
        Arrays.sort(products);

        // Print product descriptions after sorting
        for (Product prod : products) {
            System.out.println(prod.getDescription());
        }

        // Using traditional for loop to do the same:
        for (int idx = 0; idx < products.length; ++idx) {
            System.out.println(products[idx].getDescription());
        }
    }//main
}// class Main