/**
 * I chose empty entries to be <code>null</code>.
 * The other possibility would have been to model empty pages explicitly,
 * in the simplest case to add a flag (boolean attribute) to the class <code>FriendbookEntry</code>
 * that indicates whether the entry is a placeholder or not.
 * The placeholder-solution has certain benefits, as the modeling of the empty entry is explicit.
 * For example there are no errors with <code>null</code>-references possible
 * and in some cases algorithms might even become shorter and simpler without special null-checks.
 * On the other hand placeholder entries might also be easily overlooked
 * and usage of senseless default-values can then lead to erroneous calculations.
 * Also the <code>null</code>-reference problem often just moves deeper into the data-structure.
 * Therefore (and because it is simple) I just picked the <code>null</code>-solution.
 *
 * shortly: null-solution vs. placeholder-solution (pick one, know why)
 *
 * @author markus
 *
 */

class Friendbook {
    String owner;

    FriendbookEntry entry1 = null;
    FriendbookEntry entry2 = null;
    FriendbookEntry entry3 = null;
    FriendbookEntry entry4 = null;
    FriendbookEntry entry5 = null;

    public Friendbook(String owner) {
        this.owner = owner;
    }

    /**
     * if there is no entry this method returns green.
     * to fix equal occurence: green > red > blue
     */
    public Color getFavoriteColor() {
        ColorCounter counter = new ColorCounter();

        if (entry1 != null) {
            counter.add(entry1.author.preferences.favColor);
        }
        if (entry2 != null) {
            counter.add(entry2.author.preferences.favColor);
        }
        if (entry3 != null) {
            counter.add(entry3.author.preferences.favColor);
        }
        if (entry4 != null) {
            counter.add(entry4.author.preferences.favColor);
        }
        if (entry5 != null) {
            counter.add(entry5.author.preferences.favColor);
        }

        return counter.getFavoriteColor();
    }

    /**
     * if there is no entry this method also returns 100%
     */
    public double getWomensQuota() {
        int sum = 0;
        int total = 5;
        if (entry1 == null) {
            total--;
        } else if (entry1.author.sex == Sex.FEMALE) {
            sum++;
        }
        if (entry2 == null) {
            total--;
        } else if (entry2.author.sex == Sex.FEMALE) {
            sum++;
        }
        if (entry3 == null) {
            total--;
        } else if (entry3.author.sex == Sex.FEMALE) {
            sum++;
        }
        if (entry4 == null) {
            total--;
        } else if (entry4.author.sex == Sex.FEMALE) {
            sum++;
        }
        if (entry5 == null) {
            total--;
        } else if (entry5.author.sex == Sex.FEMALE) {
            sum++;
        }
        if (total > 0) {
            return (100.0 * sum) / total;
        } else {
            return 100.0;
        }
    }
}
