Algorithm hint for second repetition lab (Spring 2024)

  • banner comment
  • import's
  • declare your class
  • declare the main method
    • declare your variables. You will need at least three (see the input statement below)
    • ready your keyboard
    • get the three inputs for the user (year, month, starting day)
    • determine the number of days in the month (set a variable)
      • A use of switch statement can be nice esp. if you don't always use the break (until done listing all that have 30 days, etc)
      • Be very careful and test fully about leap years
    • display the name of the month (a simple selection statement)
    • Use a for loop to display spaces for the "missing start days". The output should be a print not a println
    • Set a counter (that counts how many days of a week have been printed) to the start day (since you have just printed those "blanks")
    • Use a loop (a for loop would be nice) to count the days (1 to 28, 29, 30, or 31) based on the number of days in the month
      • print the current day
      • add one to the counter of the days of the week
      • if you have just printed Saturday,
        • set the counter back to zero
        • print a new line
    • make sure you finish the end of the month nicely
    • finish the main method
  • finish the class
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine