package charts;

import view.WindowFrame;
import curve.GradeCurve;
import gradebook.ClassGradebook;
import java.util.Collection;

/**
 * Histogram displays how many students have a particular percentage grade in the class.  It also
 * displays letter grade boundary bars representing the cutoffs (curve) for each letter grade.
 * Derived from 2.6.1 of the requirements.
 * @author crahm
 */
public abstract class Histogram extends WindowFrame
{
   /**
    * The curve that the histogram is based off of.
    */
   public GradeCurve curve;
   
   /**
    * The class roster that the histogram is based off of.
    */
   ClassGradebook className;
   
   /**
    * The boolean value that represents whether to show plus/minus letter grades.
    */
   boolean allowPlusMinus;
   
   /**
    * Collection of HistogramSegments that represent each portion of the histogram.
    */
   Collection<HistogramSegment> segments;

   /**
    * This method is used to modify the curve by using the histogram.  The user can manually
    * move each of the letter grade boundary bars to manipulate the curve.  This movement will
    * affect the segment whose bar is being moved as well as the segment below it. If you lower
    * the B boundary, the C segment will be affected, etc.
    * @param letter represents the segment whose boundary is being modified.
    * @param newPercentBoundary represents the new percentage boundary for that letter grade.
    */
    /*@
      requires
         //
         //letter is a valid letter in the pie chart (i.e. A, B, C, D, F).
         //
         (letter.equals("A") || letter.equals("B") || letter.equals("C") || letter.equals("D") || letter.equals("F"))
          &&
         //newPercentBoundary is a valid percentage (i.e. in between 0 and 100)
         //
         ((newPercentBoundary >= 0) && (newPercentBoundary <= 100)) ;
     /*@
       ensures
          //
          //Letter Grade Histogram Segment corresponds to letter grades in grade book.
          //
          (letter.scores.size() == className.getNumStudentsWithGrade(letter.letterGrade));
      @*/

   abstract void modifyHistogramSegment(HistogramSegment letter, int newPercentBoundary);
   
   /**
    * This method is used to allow the showing/hiding of plus/minus letter grades.  
    * This method is triggered
    * when the Allow +/- Grades checkbox is checked.
    * @param set boolean indicating whether the plus/minus grades show.
    */
   /*@
     ensures
        //
        //Allow +/- Grading check box is checked, the curve now contains +/- grades if set to true, and
        //no +/- grades if set to false.
        //
        (allowPlusMinus == set) ;
   @*/
   abstract void setAllowPlusMinus(boolean set);
}

/**
 * Histogram segement is the portion of the histogram for a particular letter grade.
 */
abstract class HistogramSegment
{
   /**
    * Collection of Scores that represent the percentages contained in the letter grade segment
    * and the number of students corresponding to them.
    */
   public Collection<Score> scores;
   
   /**
    * The letter grade that represents this segment.
    */
   public String letterGrade;   
}

/**
 * Score contains a percentage score and the number of students who currently have that percentage
 * in the class.
 */
abstract class Score
{
   /**
    * The number of students who currently have this particular percentage score in the class.
    */
   int numStudents;
   
   /**
    * The percentage score.
    */
   int percent;
}