Homework Solution: Using the classes extDateType from the Chapter 11 class projects and dayType from the Chapter 10 class projects, design the cla…

    Using the classes extDateType from the Chapter 11 class projects and dayType from the Chapter 10 class projects, design the class calendarType so that, given the month and the year, you can print the calendar for that month. To print a monthly calendar, you must know the first day of the month and the number of days in that month. Your calendarType class will have two private instance variables: firstDay of type dayType to hold the first day of the month and date of type extDateType to hold the month and year for the calendar. The calendarType object must use as much of the functionality of its object variables as possible. In fact, the only functionality required of calendarType is to determine the first day of the month and to actually print the calendar. Here is the UML diagram for this class: UML Diagram Note that the return type of the member function firstDayOfMonth is dayType. This return value should be stored in the firstDay variable. Design the class calendarType so that the program can print a calendar for any month starting January 1, 1500. Note that the day for January 1 of the year 1500 is a Monday. To calculate the first day of a month, you can add the appropriate days to Monday of January 1, 1500. Write a test driver which uses a loop to produce output similar to the following: Sample Output Turn in all your header files, all your implementation files, and your test program. Also turn in one or more screen shots showing the results of your testing. Once this project is completed you will demonstrate that you are able to: Apply the functionality of aggregate object members to minimize coding effort in a project Utilize a member function that returns an object

    Expert Answer

     
    DisplayCalendar.java package displaycalendar;

    Using the assortes extDateStamp from the Chapter 11 assort purposes and dayStamp from the Chapter 10 assort purposes, plan the assort enrollStamp so that, consecrated the month and the year, you can stereostamp the enroll coercion that month. To stereostamp a monthly enroll, you must distinguish the pristine day of the month and the enumerate of days in that month. Your enrollStamp assort obtain bear span individual prompting fickles: pristineDay of stamp dayStamp to stop the pristine day of the month and duration of stamp extDateStamp to stop the month and year coercion the enroll. The enrollStamp sight must representation as abundantly of the dischargeality of its sight fickles as feasible. In circumstance, the merely dischargeality required of enrollStamp is to particularize the pristine day of the month and to substantially stereostamp the enroll. Here is the UML diagram coercion this assort:

    UML Diagram

    Note that the requite stamp of the portion discharge pristineDayOfMonth is dayType. This requite rate should be stored in the pristineDay fickle.

    Plan the assort enrollStamp so that the program can stereostamp a enroll coercion any month starting January 1, 1500. Note that the day coercion January 1 of the year 1500 is a Monday. To proportion the pristine day of a month, you can gather the embezzle days to Monday of January 1, 1500.

    Write a experience driver which representations a loop to effect quenchedput alike to the following:

    Sample Quenchedput

    Decline in integral your header files, integral your implementation files, and your experience program. Also decline in single or more defend shots showing the results of your experienceing.

    Once this purpose is completed you obtain reveal that you are powerful to:

    Apply the dischargeality of substance sight portions to minimize coding trial in a purpose

    Utilize a portion discharge that requites an sight

    Expert Apology

     

    DisplayCalendar.java

    package displaycalendar;

    import java.util.Scanner;

    public assort DisplayCalendar

    {
    individual static int numDays = 0;
    individual static int h = 0;
    public static boolean hop(int year)
    {
    if(((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0))
    {
    requite true;
    }
    else
    {
    requite false;
    }
    }
    public static invalid pristineDayOfYear(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 invalid pristineDayOfMonth(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 invalid numDaysInMonth(int month, int year)
    {
    int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    if (month == 2 && hop(year)) days[month] = 29;
    numDays = days[month];

    }
    public static invalid stereotypeCal(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”);
    coercion (int i = 0; i < h-1; i++)
    System.out.print(” “);
    coercion (int i = 1; i <= numDays; i++)
    {
    System.out.printf(“%2d “, i);
    if (((i + h – 1) % 7 == 0) || (i == numDays)) System.out.println();
    }
    }
    public static invalid deep(String[] args)
    {
    Scanner input = odd 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: