Algorithm hint for second repetition lab (Fall 2023)

  • banner comment
  • import's
  • declare your class
  • declare the main method
    • declare your variables. You will at least need something for the number inputted, something for the result, and something for the operation
    • 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 topic: CenterForComputing > WebHome > Syllabi > CSC121SylF2023 > CSC121F2023Lab04 > CSC121F2023Lab04Hint1
Topic revision: r1 - 2023-06-19 - cathybareiss
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback