Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Calendar Printing

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I am trying to produce a calendar like the image Goal.png
However my code output can be seen in Current.png

Please could you highlight my printing error ?  

NB. I know this is not the best way to produce a calendar but the requirements are such that Strings must be used.

Desired Output
Desired Output
Current Output
Current Output
Posts: 3714
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the code decide what to print on the second and following rows?  It seems to get  some output the first row.
Saloon Keeper
Posts: 3893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably have found the errors by now, but here goes:

This line:

does not work, because the method 'printNumbers' prints a couple of newlines, ruining the idea.
Besides, every first day of a month starts on sunday.

An idea is to have a Month class (but be careful: Java has alrady a Month class), that contains a String[][] array, with the first row the names of the days (sun ... sat), and the other rows containing the days (you need a maximum of 6 rows for this). Given a Month and a day, you then need to figure out where that day needs to be placed in the array. By using Strings, it makes it easy to have empty places in the print out.

In your printing routine, you can print the rows of three consecutive months.
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
    Bookmark Topic Watch Topic
  • New Topic