Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display a yearly calendar using arrays a loops?  RSS feed

 
Augusto Celis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so my teacher gave us a calendar assignment, where we have to display each month of a year dependent on what year it is. The first day of the year is calculated (0-6 meaning Sunday-Saturday), and the user inputs the year. He has stored how many days are in each month in an array called daysPerMonth. I am so confused on how to go about this because he wants us to access the array and display that many days and display each next month. Doing this, while also accounting for the first day of the year. Can anyone help? The teacher has provided much of the code and has gives us 2 functions to fill in. Please help? I am so confused help please? Where it asks for me to implement code that is my attempt at writing some code
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your method firstDayOfNextMonth(int numDays, int firstDay) takes two arguments, the number of days in this month, and the day this month starts on. I suggest taking your calendar off the wall and playing computer and see if you can see a pattern emerge when you count off the number of days starting from the firstDay of this month. Your result needs to be >= 0 and <= 6 to indicate Sunday through Saturday of the next month.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
 
Ron McLeod
Saloon Keeper
Posts: 1601
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also posted at: https://answers.yahoo.com/question/index?qid=20160627153447AAsdGtR

Augusto - we have no problem with you posting the same question on multiple sites, but please Be Forthright When Cross Posting To Other Sites so that nobody spends their time trying to help with a problem which has already been answered elsewhere.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First step I would suggest:

Forget about formatting it nicely to start with.
Can you print out the right amount of days for each month?

Once you have that, then figure out how to print it over multiple lines.

In your printMonth method, you have declared an int[][] variable called "arr"
What is this meant to represent?

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!