Answered Essay: 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;

import java.util.Scanner;

public class DisplayCalendar

{
private static int numDays = 0;
private static int h = 0;
public static boolean leap(int year)
{
if(((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0))
{
return true;
}
else
{
return false;
}
}
public static void firstDayOfYear(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 void firstDayOfMonth(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 void numDaysInMonth(int month, int year)
{
int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

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

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

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?