hey can someone please help me to make sence of this code...please use comment above the code your explaining...thanks
import java.util.*;
import java.text.*;
public class MonthView {
/** List names of the month */
public final static String[] months = {
"January" , "February" , "March",
"April" , "May" , "June",
"July" , "August" , "September",
"October" , "November" , "December"
};
/** List the days in each month */
public final static int dom[] = {
31, 28, 31, /* jan, feb, mar */
30, 31, 30, /* apr, may, jun */
31, 31, 30, /* jul, aug, sep */
31, 30, 31 /* oct, nov, dec */
};
private void printMonth(int mm, int yy) {
// The number of days to leave blank at
// the start of this month.
int leadSpaces = 0;
System.out.println();
System.out.println(" " + months[mm] + " " + yy);
if (mm < 0 || mm > 11) {
throw new IllegalArgumentException(
"Month " + mm + " bad, must be 0-11");
}
GregorianCalendar cal = new GregorianCalendar(yy, mm, 1);
System.out.println("Su Mo Tu We Th Fr Sa");
// Compute how much to leave before before the first day of the month.
// getDay() returns 0 for Sunday.
leadSpaces = cal.get(Calendar.DAY_OF_WEEK)-1;
int daysInMonth = dom[mm];
if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) {
++daysInMonth;
}
// Blank out the labels before 1st day of the month
for (int i = 0; i < leadSpaces; i++) {
System.out.print(" ");
}
for (int i = 1; i <= daysInMonth; i++) {
// This "if" statement is simpler than messing with NumberFormat
if (i<=9) {
System.out.print(" ");
}
System.out.print(i);
if ((leadSpaces + i) % 7 == 0) { // Wrap if EOL
System.out.println();
} else {
System.out.print(" ");
}
}
System.out.println();
}
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
int month, year;
MonthView mv = new MonthView();
if (args.length == 2) {
mv.printMonth(Integer.parseInt(args[0])-1, Integer.parseInt(args[1]));
} else {
Calendar today = Calendar.getInstance();
mv.printMonth(today.get(Calendar.MONTH), today.get(Calendar.YEAR));
}
}
}