Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HW #4
- Due Date: November 20th
- Homework 4 grading rubric:
- 1. Output examples
- a. One Normal Year, 10%
- b. One Leap Year, 10%
- 2. Style
- a. Meaningful variable names, 10%
- b. Meaningful method names, 10%
- c. Comments, Total: 10%
- i. Do not comment every line. 5%
- ii. Comment non-obvious code. 5%
- d. Indentation, 10%
- e. Block comment with name and hour, 5%
- 3. Calendar,
- a. Title includes Month and Year, 5%
- b. Correct number of days in month from method, 10%
- c. Correct first day of the month, 5%
- d. Method takes firstDay and MonthLength, 10%
- e. Padding, Total: 15%
- i. Month name is centered 5%
- ii. Spacing between day numbers changes , 10%
- 1. for example: “1 “ and “10” are padded to the same length.
- f. Month starts at day 1, 5%
- ● These must be demonstrated by the student
- ○ Can handle complex logic
- ■ Can break logic into more simple subproblems
- ○ Use of while loops, and other ch5 tools.
- ○ Use of modulus
- ○ Use of methods
- ■ Return values captured and used.
- ○ Writing methods
- ○ Student has learned good style
- Problem: Write a program that prints the calendar for a given
- year.
- Top down design: Break down the problem into sub problems
- and state what you will achieve for each of the sub problems
- First we need to break down into two sub problems.
- 1. Get the user’s input
- a. Read the input(year)
- 2. Print the calendar for the year
- a. Print the calendar for each month of the year
- i. Print the title for each month in the year.
- 1. Print the month and the year
- 2. Print “Sunday Monday Tuesday
- Wednesday Thursday Friday Saturday”.
- ii. Print the body for the month
- 1. Need to know the number of the days
- for each month of the year
- 2. Need to know if the year is a leap year or
- not. A year is a leap year if it is divisible
- by 400 or if the year is divisible by 4 but
- not divisible by 100
- 3. Need to know the number for the first
- day in the month. For example November
- 1st was on a Saturday which is the 6th day
- of the week assuming that Sunday is the
- zero day of the week. To figure out
- which day is the first day of the month
- you need to do the following:
- a. Calculate the total number of days
- since 1800 up to the month of the
- year that you are trying to print the
- calendari. Calculate the total number of
- days since 1800 up to one year
- prior to the given year. Note
- that you also need to check if
- the year is a leap year or not.
- For example if the user enters
- 2014, we need to calculate how
- many days from 1800 to 2013.
- Need a for loop and in the for
- loop you need to check if the
- year is a leap year.
- ii. Add the total days from the
- beginning of the given year up
- to the month. For example if
- we are trying to print the
- calendar for the March 2014,
- then we need to add the total
- number of days in Jan and Feb
- to whatever we calculated in i.
- iii. Whatever you get from ii add 3
- to it(January 1800 was on a
- Wednesday)
- iv. Calculate the remainder of iii to
- 7, this result will tell you that
- first days of month is Sun or
- Mon or Tue, or Wed or Thu or
- Fri or Sat.4. Determine the date for thanksgiving
- 5. Now that you know the number of the
- days in the month and the day for the
- first day of the month you can print the
- calendar.
- 3. Now you can write a method that accepts the number
- of the days in the month and the first day of the month ,
- then print the body
- a. 1. If the first day of the month is for example on a
- Saturday which is the 6th day of the week then you
- need to output 5 blanks “ “.
- b. You start printing from number from 1 to the last
- day of the month.
- press m to print the calender for the month, press y to print
- the calender for the year m/y
- ¼¼§Ïm
- ÏϧÏ
- ÏϧÏEnter a valid year before 1800
- ¼¼§Ï2014
- ÏϧÏEnter the month :
- ¼¼§Ï7
- ÏÏ§Ï July 2014
- ÏϧÏ----------------------------
- ÏϧÏSun Mon Tue Wed Thu Fri Sat
- ÏÏ§Ï 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
- ÏϧÏDo you have another year to print the calender:yes/no
- ¼¼§Ïyes
- ÏϧÏpress m to print the calender for the month, press y to
- print the calender for the year m/y
- ¼¼§Ïy
- ÏϧÏ
- ÏϧÏEnter a valid year before 1800
- ¼¼§Ï2013
- ÏÏ§Ï January 2013
- ÏϧÏ----------------------------
- ÏϧÏSun Mon Tue Wed Thu Fri Sat
- ÏÏ§Ï 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
Advertisement
Add Comment
Please, Sign In to add comment