import java.util.Scanner; class Year { int year; Year() { this.year = 2000; } Year(int y) { year = (y > 1900) ? y: 1900; } Year(Year y) { year = y.year; } public static boolean isLeap(int year) { if ((year % 400) == 0) return true; if ((year % 100) == 0) return false; if ((year % 4) == 0) return true; return false; } boolean isLeap() { return isLeap(year); } int weekDay() { int date = Date.MON; // Day on 1.1.1900 int i; for (i = 1900; i < year; i++) date = (date + 365 + (isLeap(i)?1:0)) % 7; return date; } public String toString() { return "" + year; } } class Month { public final static int JAN = 1; public final static int FEB = 2; public final static int MAR = 3; public final static int APR = 4; public final static int MAY = 5; public final static int JUN = 6; public final static int JUL = 7; public final static int AUG = 8; public final static int SEP = 9; public final static int OCT = 10; public final static int NOV = 11; public final static int DEC = 12; public final static String monthShortName[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; public final static String monthFullName[] = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}; private int month; private Year year; Month(int month, int year) { this.month = ((month < JAN) || (month > DEC))? JAN: month; this.year = new Year(year); } Month(int month) { this.month = ((month < JAN) || (month > DEC))? JAN: month; this.year = new Year(); } Month() { this.month = JAN; this.year = new Year(); } Month(Month m) { this.month = m.month; this.year = new Year(m.year); } private int lastDay(int month) { switch (month) { case APR: case JUN: case SEP: case NOV: return 30; case FEB: return (year.isLeap()?29:28); default: return 31; } } int lastDay() { return lastDay(month); } int weekDay() { int i; int first = year.weekDay(); for (i=JAN; i this.month.lastDay() || day < 1) ? 1: day; } Date(int day, int month) { this.month = new Month(month); this.day = (day > this.month.lastDay() || day < 1) ? 1: day; } Date(int day) { this.month = new Month(); this.day = (day > this.month.lastDay() || day < 1) ? 1: day; } Date() { this.month = new Month(); this.day = 1; } Date(Date d) { this.month = new Month(d.month); this.day = d.day; } int weekDay() { return (this.month.weekDay() + this.day - 1) % 7; } public String toString() { return "" + day + " " + month; } } class test { public static void main(String a[]) { Scanner s = new Scanner(System.in); System.out.print("Enter day(1-31) month(1-12) year (>1900) "); int day = s.nextInt(); int month = s.nextInt(); int year = s.nextInt(); Date d = new Date(day, month, year); System.out.println(d + " is/was a " + Date.dayFullName[d.weekDay()]+".\n\n"); int [][] cal = d.month.calender(); System.out.println(d.month); int i = 0, j = 0; for (j=0; j<7; j++) System.out.print(" " + Date.dayShortName[j]); System.out.println(""); for (i=0; i<5; i++) { for (j=0; j<7; j++) { if (cal[i][j] == 0) System.out.print(" "); else if (cal[i][j] < 10) System.out.print(" "+cal[i][j]); else System.out.print(" "+cal[i][j]); } System.out.println(""); } } }