• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to display a yearly calendar using arrays a loops?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 5076
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also posted at: http://www.dreamincode.net/forums/topic/394829-how-to-display-the-year-calendar-using-a-loop-in-java/
 
Marshal
Posts: 4664
583
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic