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 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:

    UML Diagram

    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:

    Sample Extinguishedput

    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

    Expert Rejoinder

     

    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: