
import java.util.*;

public class TutorTest_InnerClass_anonima_ArrayList
{
   public static void main(String[] args)
   {


      // construct a Tutor object as nested anonymous inner class
      Bonused expert = new Bonused()
        {  String name="Paolo Rossi";
           double frequency=80.;
           private double bonus=0.;

           public String getName()
	     {

	        return name;
	     }

	   public double getFrequency()
	     {

	        return frequency + bonus;
	     }

           public void setBonus(double b)
	     {
	        bonus = b;
	     }
           GregorianCalendar calendar
             = new GregorianCalendar(2005, 10, 5);
           // GregorianCalendar uses 0 for January
           Date enrollmentDay = calendar.getTime();
        };

      expert.setBonus(5);

      ArrayList squadra = new ArrayList();
      squadra.ensureCapacity(3);

	  //start a cronometer:
	  GregorianCalendar cronometer = new GregorianCalendar();
	  int timeAtStart = calendar.getTime(Calendar.MILLISECOND);

      // fill the squadra array with Tutor and Student objects

      squadra.add(expert);
      squadra.add(new Student("Mario Bianchi", 70.,
         2000, 11, 1));
      squadra.add(new Student("Carla Verdi", 60.,
         2000, 11, 1));
 	  squadra.add(new Student("Umberto Neri", 60.,
         2000, 11, 1));
      squadra.add(new Student("Carlo Viola", 60.,
         2000, 11, 1));
      // print out information about all Student objects
         //Bonused e=(expert.getClass)squadra.get(1);
         System.out.println("name=" + expert.getName()
            + ", frequency=" + expert.getFrequency());
      //double the size repeatedly:
      int volte=15;
      for (j=0; j<volte; j++)
        {
			int numeroElementi = squadra.getSize();
         	for (i=0; i<numeroElementi; i++)
				squadra.add(squadra.get(i));
	    }
      int timeAtEnd = calendar.getTime(Calendar.MILLISECOND);
      int timeElapsed = timeAtEnd-timeAtStart;
      NumberFormat quantiMillisecondi = NumberFormat.getTimeInstance();
      System.out.println(quantiMillisecondi.format(timeElapsed));

      /* for (int i = 1; i < squadra.size(); i++)
      {
         Student e = (Student)squadra.get(i);
         System.out.println("name=" + e.getName()
            + ", frequency=" + e.getFrequency());
      }*/
   }
}

class Student
{
   public Student(String n, double s,
      int year, int month, int day)
   {
      name = n;
      frequency = s;
      GregorianCalendar calendar
         = new GregorianCalendar(year, month - 1, day);
         // GregorianCalendar uses 0 for January
      enrollmentDay = calendar.getTime();
   }

   public String getName()
   {
      return name;
   }

   public double getFrequency()
   {
      return frequency;
   }

   public Date getEnrollmentDay()
   {
      return enrollmentDay;
   }

   public void raiseFrequency(double byPercent)
   {
      double raise = frequency * byPercent / 100;
      frequency += raise;
   }

   private String name;
   protected double frequency;
   private Date enrollmentDay;
}

interface Bonused
{
	//public abstract Tutor(String n, double s,int year, int month, int day);
	public abstract double getFrequency();
        public abstract String getName();
	public abstract void setBonus(double b);
}

