/**
 * A class that contains several examples
 * of indicators methods.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class IndicatorMethods {

    private static final int DRINKING_AGE = 21;
    
    /**
     * A method to hold the fragments.
     *
     * @param args  The command-line arguments
     */
    public static void main(String[] args) {
        int converse, indicatorNZ, indicatorT, indicator, intermediate;
        int max, threshold, value;
        
        value = 11;        
        threshold = 17;
        max = 100;        


//[nonzero
        indicatorNZ = (value + max) / (max + 1);
//]nonzero

        double repeatOffenderPenalty, baseFine, totalFine;        
        int priors = 1;        
//[parking
        baseFine = 10.00;
        repeatOffenderPenalty = 35.00;        
        totalFine = baseFine + (indicator(priors, 1) * repeatOffenderPenalty);
//]parking
        System.out.printf("totalFine: %f\n", totalFine);


//[intermediate1
        intermediate = value / threshold;
//]intermediate1

//[intermediate2
        indicatorT = (intermediate + max) / (max + 1);
//]intermediate2

//[threshold
        indicatorT = ((value / threshold) + max) / (max + 1);
//]threshold


        int shows; 
        int sold = 1;
//[review0
        if (sold >= 1) {
            shows = 1;
        } else {
            shows = 0;
        }
//]review0

//[shows
        shows = indicator(sold, 1);
//]shows

        double baseRate, ageSurcharge, rate, multiSurcharge;
        int extraDrivers = 1;
        int minimumAge = 28;
        int ageThreshold;
        int multiThreshold;
        
//[rental0
        baseRate = 19.95;

        ageSurcharge = 10.00;
        ageThreshold = 25;

        multiSurcharge = 5.00;
        multiThreshold = 1;
//]rental0

//[rental1
        rate = baseRate 
            + (1 - indicator(minimumAge, ageThreshold)) * ageSurcharge
            + indicator(extraDrivers, multiThreshold) * multiSurcharge;
//]rental1
        System.out.println(rate);        

        double b = 0, m = 0, h = 0, a = 0;
        char s = 'f';        
//[bmr
        b = 5.00 + 10.00 * m + 6.35 * h - 5.00 * a - 161.00 * indicator(s);
//]bmr

        boolean isLegal;
        int age;
        age = 27;
//[old0
        if (age >= DRINKING_AGE) {
            isLegal = true;
        } else {
            isLegal = false;
        }
//]old0

//[old1
        isLegal = (age >= DRINKING_AGE);        
//]old1
    }

//[aindicator
    /**
     * Calculate a threshold indicator from a value, threshold,
     * and maximum value.
     *
     * @param value      The value of interest
     * @param threshold  The threshold value
     * @param max        The maximum possible value
     * @return 0 if the value is less than the threshold; 1 otherwise
     */
    public static int aindicator(int value, int threshold, int max) {
        return ((value / threshold) + max) / (max + 1);
    }
//]aindicator

//[review1
    /**
     * Calculate the number of shows from the number of tickets
     * sold for a particular show time.
     *
     * @param  sold  The number of tickets sold for a particular show time
     * @return 0 if sold is 0; 1 otherwise
     */
    public static int shows(int sold) {
        if (sold >= 1) {
            return 1;
        } else {
            return 0;
        }
    }
//]review1

//[indicator
    /**
     * Calculate a threshold indicator from a value and threshold.
     *
     * @param value      The value of interest
     * @param threshold  The threshold value
     * @return 0 if the value is less than the threshold; 1 otherwise
     */
    public static int indicator(int value, int threshold) {
        if (value >= threshold) {
            return 1;
        } else {
            return 0;
        }
    }
//]indicator

//[female
    /**
     * Return 1 if the person's sex is female and 0 otherwise.
     *
     * @param sex  The person's sex ('F' or 'M')
     * @return     1 if the person is female, and 0 otherwise
     */
    public static int indicator(char sex) {
        if ((sex == 'F') || (sex == 'f')) {
            return 1;
        } else {
            return 0;
        }
    }
//]female
}
