package charts;

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

/**
 * The Pie Chart contains information about what percentage of students are receiving each letter
 * grade for a particular class.
 * Derived from 2.6.2 of the requirements.
 * @author crahm
 */
public abstract class PieChart extends WindowFrame
{
   /**
    * The curve which the pie chart is based off of.
    */
   public GradeCurve curve;
   
   /**
    * The class roster which the pie chart is based off of.
    */
   ClassGradebook className;
   
   /**
    * The collection of pie slices.  Each slice represents a portion of the students receiving a
    * particular letter grade.
    */
   Collection<Slice> slices;

   /**
    * This method is used to modify a particular slice.  The user is able to modify how big a particular
    * slice is by dragging a slice boundary.  This boundary is in between two letter grade slices.  Therefore
    * modifying the boundary between two slices modifies both those two slices.
    * @param letter1 This Slice parameter represents one of the letter grades the modification lies
    * between.
    * @param letter2 This Slice parameter represents one of the letter grades the modification lies
    * between.
    * @param newSlicePercentage1 This double parameter represents one of the new slice's percentages.
    * @param newSlicePercentage2 This double parameter represents one of the new slice's percentages.
    */
    /*@
      requires
      //
      //letter1 and letter 2 are valid letters in the pie chart (i.e. A, B, C, D, F).
      //
      (letter1.equals("A") || letter1.equals("B") || letter1.equals("C") || letter1.equals("D") || letter1.equals("F"))
       &&
      (letter2.equals("A") || letter2.equals("B") || letter2.equals("C") || letter2.equals("D") || letter2.equals("F")
       &&
      //newSlicePercentage1 and newSlicePercentage2 are valid percentages (i.e. sum less than 100%, positive)
      //
      ((newSlicePercentage1 + newSlicePercentage2) <= 100) && (newSlicePercentage1 >= 0) && (newSlicePercentage2 >= 0)) ;
   /*@
       ensures
          //
          //Letter Grade Slice corresponds to letter grades in grade book.
          //
          (letter1.numStudents == className.getNumStudentsWithGrade(letter1.letterGrade)) &&
          (letter2.numStudents == className.getNumStudentsWithGrade(letter2.letterGrade));
    @*/  
    
   abstract void modifySlice(Slice letter1, Slice letter2, double newSlicePercentage1, double newSlicePercentage2);

}

/**
 * The Slice is a portion of the Pie Chart.  Slice contains the letter grade it represents as well as
 * how many students have that letter grade for a given class.
 */
abstract class Slice
{
   /**
    * The number of students who are in this slice (who have the letter grade in the class).
    */
   public int numStudents;
   
   /**
    * The letter grade that the slice represents.
    */
   String letterGrade;
}