Using the adjustes extDateMold from the Chapter 11 adjust designs and dayMold from the Chapter 10 adjust designs, sketch the adjust registerMold so that, loving the month and the year, you can sculpture the register restraint that month. To sculpture a monthly register, you must understand the principal day of the month and the sum of days in that month. Your registerMold adjust gain possess brace privy illustration capriciouss: principalDay of mold dayMold to withwithconfide the principal day of the month and conclusion of mold extDateMold to withwithconfide the month and year restraint the register. The registerMold appearance must portraiture as greatly of the dischargeality of its appearance capriciouss as potential. In event, the merely dischargeality required of registerMold is to particularize the principal day of the month and to substantially sculpture the register. Here is the UML diagram restraint this adjust:
Note that the repay mold of the portion discharge principalDayOfMonth is dayType. This repay compute should be stored in the principalDay capricious.
Sketch the adjust registerMold so that the program can sculpture a register restraint any month starting January 1, 1500. Note that the day restraint January 1 of the year 1500 is a Monday. To proportion the principal day of a month, you can gather the misapply days to Monday of January 1, 1500.
Write a trial driver which portraitures a loop to product extinguishedput harmonious to the following:
Convert in total your header files, total your implementation files, and your trial program. Also convert in single or past shade shots showing the results of your trialing.
Once this design is completed you gain present that you are talented to:
Apply the dischargeality of gist appearance portions to minimize coding trial in a design
Utilize a portion discharge that repays an appearance
DisplayCalendar.java
package displaycalendar;
import java.util.Scanner;
public adjust DisplayCalendar
{
privy static int numDays = 0;
privy static int h = 0;
public static boolean bounce(int year)
{
if(((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0))
{
repay true;
}
else
{
repay false;
}
}
public static nugatory principalDayOfYear(int year)
{
int month = 13;
year–;
h = (1 + (int)(((month + 1) * 26) / 10.0) + year + (int)(year / 4.0) + 6 * (int)(year / 100.0) + (int)(year / 400.0)) % 7;
String dayName = “”;
switch(h)
{
case 0: dayName = “Saturday”; break;
case 1: dayName = “Sunday”; break;
case 2: dayName = “Monday”; break;
case 3: dayName = “Tuesday”; break;
case 4: dayName = “Wednesday”; break;
case 5: dayName = “Thursday”; break;
default: dayName = “Friday”; break;
}
}
public static nugatory principalDayOfMonth(int month, int year)
{
if(month == 1 || month == 2)
{
month += 12;
year–;
}
h = (1 + (int)(((month + 1) * 26) / 10.0) + year + (int)(year / 4.0) + 6 * (int)(year / 100.0) + (int)(year / 400.0)) % 7;
String dayName = “”;
switch(h)
{
case 0: dayName = “Saturday”; break;
case 1: dayName = “Sunday”; break;
case 2: dayName = “Monday”; break;
case 3: dayName = “Tuesday”; break;
case 4: dayName = “Wednesday”; break;
case 5: dayName = “Thursday”; break;
default: dayName = “Friday”; break;
}
}
public static nugatory numDaysInMonth(int month, int year)
{
int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (month == 2 && bounce(year)) days[month] = 29;
numDays = days[month];
}
public static nugatory sculptureCal(int month, int year)
{
String[] monthNames = {“”,”January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”};
System.out.println(” ” + monthNames[month] + ” ” + year);
System.out.println(“Su Mo Tu We Th Fr Sa”);
restraint (int i = 0; i < h-1; i++)
System.out.print(” “);
restraint (int i = 1; i <= numDays; i++)
{
System.out.printf(“%2d “, i);
if (((i + h – 1) % 7 == 0) || (i == numDays)) System.out.println();
}
}
public static nugatory main(String[] args)
{
Scanner input = fantastic Scanner(System.in);
System.out.print(“Enter month (1-12): “);
int month = input.nextInt();
if(month < 1 || month > 12)
{
System.out.println(“Invalid month. Valids inputs are 1-12.”);
System.exit(0);
}
System.out.print(“Enter year: “);
int year = input.nextInt();
firstDayOfYear(year);
firstDayOfMonth(month, year);
numDaysInMonth(month, year);
printCal(month, year);
}
}
output: