I am trying to create a method that counts the number of each full months in an array. my array contains the dates in MM/dd/yyyy format. The array can contain dates starting from any date and ending at any date. The dates are in order from oldest to newest and only contain weekdays.
For example, if the array has dates from 6/15/2010 to 1/15/2012, it would return an array of: jan = 1, feb = 1, mar = 1, apr = 1, may = 1, jun = 1, jul = 2, aug = 2, sep = 2, oct = 2, nov = 2, dec = 2
I was hoping someone could give me some hints, here is what i have so far:
double[] months = new double[12];
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat yyyy = new SimpleDateFormat("yyyy");
for(int ii = 0 ; ii < array.length-length ; ii++){
date = (Date)formatter.parse(array[ii][0]);
String currentDateMY = sdf.format(date);
String currentDateYYYY = yyyy.format(date);
date = (Date)formatter.parse(array[ii+1][0]);
String nextDateMY = sdf.format(date);
if (!currentDateMY.equals(nextDateMY)){
date = (Date)formatter.parse(array[ii][0]);
sdf = new SimpleDateFormat("MM");
String currentDateM = sdf.format(date);
if (currentDateM.equals("01")) months[0] = jan++;
if (currentDateM.equals("02")) months[1] = feb++;
if (currentDateM.equals("03")) months[2] = mar++;
if (currentDateM.equals("04")) months[3] = apr++;
if (currentDateM.equals("05")) months[4] = may++;
if (currentDateM.equals("06")) months[5] = jun++;
if (currentDateM.equals("07")) months[6] = jul++;
if (currentDateM.equals("08")) months[7] = aug++;
if (currentDateM.equals("09")) months[8] = sep++;
if (currentDateM.equals("10")) months[9] = oct++;
if (currentDateM.equals("11")) months[10] = nov++;
if (currentDateM.equals("12")) months[11] = dec++;
}
}