Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the
Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class.
(Code given below)
import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayListmonths; private int number; public Year() { this(2013); } public Year(int number) { this.number = number; initializeMonths(); } public Year(ArrayList months, int number) { this.months = months; this.number = number; } public void initializeMonths() { months = new ArrayList (12); months.add(new Month("January", number)); months.add(new Month("February", number)); months.add(new Month("March", number)); months.add(new Month("April", number)); months.add(new Month("May", number)); months.add(new Month("June", number)); months.add(new Month("July", number)); months.add(new Month("August", number)); months.add(new Month("September", number)); months.add(new Month("October", number)); months.add(new Month("November", number)); months.add(new Month("December", number)); } public static boolean isLeapYear(int year) { if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) { return true; } return false; } public void printCalendar() { Month month; Iterator it = months.iterator(); while (it.hasNext()) { month = it.next(); month.printCalendar(); } } } class Month { private ArrayList days; private String name; private int year; public Month() { days = new ArrayList (); name = new String(); year = 0; } public Month(String name, int year) { this.name = name; this.year = year; initializeDays(); } public Month(ArrayList days, String name, int year) { this.days = days; this.name = name; this.year = year; } public int convertNameToNumber() { int nameToNumber = 1; if (name.equals("February")) { nameToNumber = 2; } else if (name.equals("March")) { nameToNumber = 3; } else if (name.equals("April")) { nameToNumber = 4; } else if (name.equals("May")) { nameToNumber = 5; } else if (name.equals("June")) { nameToNumber = 6; } else if (name.equals("July")) { nameToNumber = 7; } else if (name.equals("August")) { nameToNumber = 8; } else if (name.equals("September")) { nameToNumber = 9; } else if (name.equals("October")) { nameToNumber = 10; } else if (name.equals("November")) { nameToNumber = 11; } else if (name.equals("December")) { nameToNumber = 12; } return nameToNumber; } public int determineNumberOfDays() { int total; if ( name.equals("January") || name.equals("March") || name.equals("May") || name.equals("July") || name.equals("August") || name.equals("October") || name.equals("December") ) { total = 31; } else if ( name.equals("April") || name.equals("June") || name.equals("September") || name.equals("November") ) { total = 30; } else { if (Year.isLeapYear(year)) { total = 29; } else { total = 28; } } return total; } public int determineNumberOfDays(int monthNumber) { if (monthNumber == 2) { if (Year.isLeapYear(year)) { return 29; } else { return 28; } } else if ( monthNumber == 4 || monthNumber == 6 || monthNumber == 9 || monthNumber == 11 ) { return 30; } else { return 31; } } public int determineStartDayOffset() { //get total number of days since 1/1/1800 int i, monthNumber, startDayOffset, startDayOffset1800 = 3; long totalNumberOfDays = startDayOffset1800; for (i = 1800; i < year; i++) { if (Year.isLeapYear(i)) { totalNumberOfDays = totalNumberOfDays + 366; } else { totalNumberOfDays = totalNumberOfDays + 365; } } monthNumber = convertNameToNumber(); for (i = 0; i < monthNumber; i++) { totalNumberOfDays = totalNumberOfDays + determineNumberOfDays(i + 1); } startDayOffset = (int) (totalNumberOfDays % 7); return startDayOffset; } public ArrayList getDays() { return days; } public String getName() { return name; } public void initializeDays() { int i, startDayOffset; int numberOfDays = determineNumberOfDays(); String dayName = new String(); days = new ArrayList (numberOfDays); startDayOffset = determineStartDayOffset(); for (i = 0; i < numberOfDays; i++) { switch ((i + startDayOffset) % 7) { case 0: dayName = "Sunday"; break; case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; case 3: dayName = "Wednesday"; break; case 4: dayName = "Thursday"; break; case 5: dayName = "Friday"; break; case 6: dayName = "Saturday"; break; default: dayName = "Week Day"; } days.add(new Day(dayName, (i + 1))); } } public void printCalendar() { int i, numberOfDays, startDayOffset; System.out.println(); printTitle(); numberOfDays = determineNumberOfDays(); startDayOffset = determineStartDayOffset(); for (i = 0; i < startDayOffset; i++) { System.out.print(" "); } for (i = 0; i < numberOfDays; i++) { if ((i > 0) && (i + startDayOffset) % 7 == 0) { System.out.println(); } days.get(i).printDay(); } System.out.println(); } public void printInfo() { System.out.println(toString()); } public void printTitle() { System.out.println(" " + name + ", " + year); System.out.println("-----------------------------"); System.out.println(" Sun Mon Tue Wed Thu Fri Sat"); } public void setDays(ArrayList days) { this.days = days; } public void setName(String name) { this.name = name; } public String toString() { String data = ""; for (Day day : days) { data = data + day.toString() + " "; } return data; } } class Day { private String name; private int number; public Day() { number = 0; name = new String(); } public Day(String name, int number) { this.name = name; this.number = number; } public String getName() { return name; } public int getNumber() { return number; } public void printDay() { if (number < 10) { System.out.print(" "); } System.out.print(" " + number); } public void printInfo() { System.out.println(toString()); } public void setName(String name) { this.name = name; } public void setNumber(int number) { this.number = number; } public String toString() { return "Name: " + name + " " + "Number: " + number + " "; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started