In: Computer Science
JAVA Please
Given the following
// abbreviated Month names
static private final String [] MONTH_NAMES = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
// day length of each month
static private final int [] MONTH_SIZES = {
31, 28, 31,30,31, 30, 31, 31, 30, 31, 30, 31
};
Write code to show the Julian Calendar and use formatting to format
the code in colomuns and rows
Use nested loops please
If you have any doubts, please give me comment...
public class JulianCalendar {
// Max number of Days in a month
static private final int MAX_DAY = 31;
// abbreviated Month names
static private final String[] MONTH_NAMES = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec" };
// day length of each month
static private final int[] MONTH_SIZES = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/**
* display The "DAY" Column Heading
*/
static private void displayDayHeading() {
System.out.printf("%6s", "Day");
}
/**
* display Month names between Day .... Day
*/
static private void displayHeading() {
displayDayHeading();
for (int i = 0; i < MONTH_NAMES.length; ++i) {
System.out.printf("%5s", MONTH_NAMES[i]);
}
displayDayHeading();
}
static public void display() {
displayHeading();// display heading
for(int i=0; i<MAX_DAY; i++){
System.out.printf("\n%6d", i+1);
for(int j=0; j<MONTH_NAMES.length; j++){
int sum = 0;
for(int k=0; k<j; k++){
sum += MONTH_SIZES[k];
}
if(sum+MONTH_SIZES[j]>=sum+i+1)
System.out.printf(" %03d", sum+i+1);
else
System.out.printf(" %03d", 0);
}
System.out.printf("%6d", i+1);
}
System.out.println();
}
/**
* @param args
*/
public static void main(String[] args) {
// invoke display method
display();
}
}