COSC 117

 

Programing Assignment #3

 

DESCRIPTION: Design and write a program that will print a month given by the user.  It will allow the user to print more than one month if desired. 

 

CLARIFICATION: The input of this program is interactive (received from the keyboard by the person running the program).  The user is asked to input a month (numbers from 1 to 12 inclusive), the starting day of the month (the day of the week the month begins (this will be a number from 1 to7 inclusive.  The user is asked to state if this is a leap year.  The program should check to see if all three input data values are in the correct range.  Numbers between 1 and 12 for the month, numbers between 1and 7 for the starting day and a word beginning with either y or n for the leap year.  The program will then print this month with the name of the month centered and the days of the month by weeks.  The calculation of the number of days in the month should be in a function and the printing of the days itself should be in a method distinct from the main method.  A do while loop should be used that will continue the process if the user wants more than one month to be printed. 

 

Details of implementation:  You will have to use nested loops.  You should use all three types of loops: do while (outermost loop because we will assume that at least one month will be printed), while loops( used to check data entry) and for loops in the process of the printing of the month. 

 

You must call the class CalendarMonth

 

Extra Credit:  Develop a program that will input the first day of January and whether or not it is a leap year and then it will print the complete year.  NOTE:  You will not have to use a do while outer loop since it will run the program only once.  It should have all the data checks as the original problem. 

 

 


Sample Input/Output  (Not extra credit form)

 

Please input the month an integer between 1 and 12  1 for January 2 for February etc.

2

Please input the day of the week that the month begins

 It must be a number between 1 and 7 1 for Sunday, 2 for Tuesday etc.

9

Bad Data Try again

Please input the day of the week that the month begins

It must be a number between 1 and 7 1 for Sunday, 2 for Tuesday etc.

7

Is this a leap year please answer yes or no

w

Bad entry please input yes or no

Is this a leap year please answer yes or no

y

            February

 

                         1 

 2   3   4   5   6   7   8 

 9  10  11  12  13  14  15 

16  17  18  19  20  21  22 

23  24  25  26  27  28  29 

 

 

 

Would you like another month printed, type yes or no

y

Please input the month an integer between 1 and 12  1 for January 2 for February etc.

45

Bad data it must be a number between 1 and 12:  Try again

Please input the month an integer between 1 and 12  1 for January 2 for February etc.

12

Please input the day of the week that the month begins

 It must be a number between 1 and 7 1 for Sunday, 2 for Tuesday etc.

2

Is this a leap year please answer yes or no

n

            December

 

     1   2   3   4   5   6 

 7   8   9  10  11  12  13 

14  15  16  17  18  19  20 

21  22  23  24  25  26  27 

28  29  30  31 

 

 

 

Would you like another month printed, type yes or no

n

 


I.  You must develop an Algorithm that includes the following.

A.    Description and Clarification

B.    Sample Input/Output. 

The specs give you one sample I/O.  You should include at least 1 more

     C.   Variable List

            1.         Input Variables

            2.         Output Variables

            3.         Other Variables

     D.   A Tree Structure  (This does not have to be detailed but should give an overall approach to the problem

     E.    The algorithm should be generic, not Java instructions and it can be as detailed as necessary to write the program.  In other words basic statements of output for example do not have to be detailed. 

 

II.         You must write the program so that it runs properly.

A.        Heading comments

            1.         Programmers name

            2.         Assignment number

            3.         Class and Section

            4.         Date

            5.         Description of the program

                        Constant and variable declarations (tell what each do)

           

D.        Body of the program that is well documented with appropriate comments about the logic of the program.