Guest User

Untitled

a guest
Nov 20th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. HW #4
  2. Due Date: November 20th
  3. Homework 4 grading rubric:
  4. 1. Output examples
  5. a. One Normal Year, 10%
  6. b. One Leap Year, 10%
  7. 2. Style
  8. a. Meaningful variable names, 10%
  9. b. Meaningful method names, 10%
  10. c. Comments, Total: 10%
  11. i. Do not comment every line. 5%
  12. ii. Comment non-obvious code. 5%
  13. d. Indentation, 10%
  14. e. Block comment with name and hour, 5%
  15. 3. Calendar,
  16. a. Title includes Month and Year, 5%
  17. b. Correct number of days in month from method, 10%
  18. c. Correct first day of the month, 5%
  19. d. Method takes firstDay and MonthLength, 10%
  20. e. Padding, Total: 15%
  21. i. Month name is centered 5%
  22. ii. Spacing between day numbers changes , 10%
  23. 1. for example: “1 “ and “10” are padded to the same length.
  24. f. Month starts at day 1, 5%
  25. ● These must be demonstrated by the student
  26. ○ Can handle complex logic
  27. ■ Can break logic into more simple subproblems
  28. ○ Use of while loops, and other ch5 tools.
  29. ○ Use of modulus
  30. ○ Use of methods
  31. ■ Return values captured and used.
  32. ○ Writing methods
  33. ○ Student has learned good style
  34. Problem: Write a program that prints the calendar for a given
  35. year.
  36. Top down design: Break down the problem into sub problems
  37. and state what you will achieve for each of the sub problems
  38. First we need to break down into two sub problems.
  39. 1. Get the user’s input
  40. a. Read the input(year)
  41. 2. Print the calendar for the year
  42. a. Print the calendar for each month of the year
  43. i. Print the title for each month in the year.
  44. 1. Print the month and the year
  45. 2. Print “Sunday Monday Tuesday
  46. Wednesday Thursday Friday Saturday”.
  47. ii. Print the body for the month
  48. 1. Need to know the number of the days
  49. for each month of the year
  50. 2. Need to know if the year is a leap year or
  51. not. A year is a leap year if it is divisible
  52. by 400 or if the year is divisible by 4 but
  53. not divisible by 100
  54. 3. Need to know the number for the first
  55. day in the month. For example November
  56. 1st was on a Saturday which is the 6th day
  57. of the week assuming that Sunday is the
  58. zero day of the week. To figure out
  59. which day is the first day of the month
  60. you need to do the following:
  61. a. Calculate the total number of days
  62. since 1800 up to the month of the
  63. year that you are trying to print the
  64. calendari. Calculate the total number of
  65. days since 1800 up to one year
  66. prior to the given year. Note
  67. that you also need to check if
  68. the year is a leap year or not.
  69. For example if the user enters
  70. 2014, we need to calculate how
  71. many days from 1800 to 2013.
  72. Need a for loop and in the for
  73. loop you need to check if the
  74. year is a leap year.
  75. ii. Add the total days from the
  76. beginning of the given year up
  77. to the month. For example if
  78. we are trying to print the
  79. calendar for the March 2014,
  80. then we need to add the total
  81. number of days in Jan and Feb
  82. to whatever we calculated in i.
  83. iii. Whatever you get from ii add 3
  84. to it(January 1800 was on a
  85. Wednesday)
  86. iv. Calculate the remainder of iii to
  87. 7, this result will tell you that
  88. first days of month is Sun or
  89. Mon or Tue, or Wed or Thu or
  90. Fri or Sat.4. Determine the date for thanksgiving
  91. 5. Now that you know the number of the
  92. days in the month and the day for the
  93. first day of the month you can print the
  94. calendar.
  95. 3. Now you can write a method that accepts the number
  96. of the days in the month and the first day of the month ,
  97. then print the body
  98. a. 1. If the first day of the month is for example on a
  99. Saturday which is the 6th day of the week then you
  100. need to output 5 blanks “ “.
  101. b. You start printing from number from 1 to the last
  102. day of the month.
  103.  
  104. press m to print the calender for the month, press y to print
  105. the calender for the year m/y
  106. ¼¼§Ïm
  107. ÏϧÏ
  108. ÏϧÏEnter a valid year before 1800
  109. ¼¼§Ï2014
  110. ÏϧÏEnter the month :
  111. ¼¼§Ï7
  112. ÏÏ§Ï July 2014
  113. ÏϧÏ----------------------------
  114. ÏϧÏSun Mon Tue Wed Thu Fri Sat
  115. ÏÏ§Ï 1 2 3 4 5 ÏϧÏ6 7 8 9 10 11 12
  116. ÏϧÏ13 14 15 16 17 18 19
  117. ÏϧÏ20 21 22 23 24 25 26
  118. ÏϧÏ27 28 29 30 31
  119. ÏϧÏDo you have another year to print the calender:yes/no
  120. ¼¼§Ïyes
  121. ÏϧÏpress m to print the calender for the month, press y to
  122. print the calender for the year m/y
  123. ¼¼§Ïy
  124. ÏϧÏ
  125. ÏϧÏEnter a valid year before 1800
  126. ¼¼§Ï2013
  127. ÏÏ§Ï January 2013
  128. ÏϧÏ----------------------------
  129. ÏϧÏSun Mon Tue Wed Thu Fri Sat
  130. ÏÏ§Ï 1 2 3 4 5
  131. ÏϧÏ6 7 8 9 10 11 12
  132. ÏϧÏ13 14 15 16 17 18 19
  133. ÏϧÏ20 21 22 23 24 25 26
  134. ÏϧÏ27 28 29 30 31
Advertisement
Add Comment
Please, Sign In to add comment