/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/StockList.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.lab3_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class StockList {

    private Stock[] list;

    // A constructor that  creates a list of type stock
    public StockList(int listSize)
    {
        list = new Stock[listSize];
        createListObjects();
    }

    // Creates a list of Fan objects from User's input
    private void createListObjects()
    {
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < list.length; ++i) {
            Stock stock = new Stock();
            System.out.println("Enter Stock data for stock " + (i + 1)
                    + ": symbol, name, previous closing price, and current price");
            String symbol = scan.next();
            String name = scan.next();
            double previousClosingPrice = scan.nextDouble();
            double currentPrice = scan.nextDouble();
            stock.setSymbol(symbol);
            stock.setName(name);
            stock.setPreviousClosingPrice(previousClosingPrice);
            stock.setCurrentPrice(currentPrice);
            list[i] = stock;
            System.out.println("----------------------------------------");
        }
    }

    @Override
    public String toString()
    {
        String s = "StockList{" + "list=\n";
        for (int i = 0; i < list.length; ++i) {
            s += list[i].toString() + "\n-----------------------\n";
        }
        s += '}';
        return s;
    }

    public void sortByChangeInPercentage()
    {
        for (int i = 0; i < list.length - 1; ++i) {
            for (int j = i + 1; j < list.length; ++j) {
                if (list[i].getChangePercent() > list[j].getChangePercent()) {
                    Stock temp = list[i];
                    list[i] = list[j];
                    list[j] = temp;
                }
            }
        }
    }
    public static void main(String[] args)
    {
        StockList stockList = new StockList(3);
        System.out.println(stockList);
        stockList.sortByChangeInPercentage();
        System.out.println(stockList);
    }
}