I need to allocate for each day a list of dates of a range period, a certain String out of three possible (Class A, Class B, Class C), so that the result is sequential until all the dates in the list are filled out .
Follow the code made so far ....
import java.util.*;
import java.text.*;
public class CalcularDatas {
public static void main (String[] args) throws ParseException {
String[] myArray = {"Turma A", "Turma B", "Turma C"};
List<String> arrayList = new ArrayList<String> (Arrays.asList(myArray));
DateFormat df = new SimpleDateFormat ("dd/MM/yyyy");
Date dt1 = df.parse ("01/10/2016"); // Data inicial
Date dt2 = df.parse ("10/10/2016"); //
Calendar cal1 = Calendar.getInstance();
cal1.setTime (dt1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime (dt2);
cal2.add(Calendar.DATE,1);
for (Calendar cal = cal1; cal.compareTo (cal2) <= 0; cal.add (Calendar.DATE, 1)) {
System.out.println (df.format (cal.getTime())+ arrayList);
}
}
}
Output:
01/10/2016 [Class A, Class B, Class C]
02/10/2016 [Class A, Class B, Class C]
03/10/2016 [Class A, Class B, Class C]
04/10/2016 [Class A, Class B, Class C]
05/10/2016 [Class A, Class B, Class C]
06/10/2016 [Class A, Class B, Class C]
07/10/2016 [Class A, Class B, Class C]
10/08/2016 [Class A, Class B, Class C]
09/10/2016 [Class A, Class B, Class C]
10/10/2016 [Class A, Class B, Class C]
11/10/2016 [Class A, Class B, Class C]
Expected Mode:
01/10/2016 Class A 10/02/2016 Class B 03/10/2016 Class C 10/4/2016 Class A 05/10/2016 Class B 10/06/2016 Class C 10/7/2016 Class A 10/10/2016 Class B 10/9/2016 Class C 10/10/2016 Class A 10/11/2016 Class B