This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Calendar Code Help  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the code I have, and when I run it, it works to an extent. I wanted the days to be slid over x amount of spaces depending on what the user would input (Sun = 0, Mon = 1... etc.) but that's where i'm stuck, I've tried myself, but when i do the numbers don't carry over but instead pop out of the grid
 
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you cut&paste a session here so that we can see the input and output you are talking about?
 
Nick Tran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enter Day:
3
Enter the number of days in each month:
29
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29

All the the numbers are lined up good on the right but it won't start at Tuesday (which is the 3rd day) and when i tried hard coding if statements to use the user input amount of days to move a x amount of spaces, the loop still continues to loop which leads the numbers to go beyond Sat

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29
 
Nick Tran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nick Tran wrote:All the the numbers are lined up good on the right but it won't start at Tuesday (which is the 3rd day)...


Well that's wrong for a start. If Sunday=0, then 3 is Wednesday.

Also: your loops only work for 5 x 7 days. What if the month is 31 days long and starts on a Saturday?

My advice: Turn off your computer and get out lots of paper and work out how YOU would do this. You clearly have the grid printing working, now you just need to work out how to "offset" the days when a month doesn't start on a Sunday.

Programming is about thinking, not about coding.

HIH

Winston
 
Marshal
Posts: 59717
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nick Tran wrote:. . .

Why are you creating a new PrintWriter when System.out already is a PrintWriter? Since you are not using any formatting tags, why not simply write:-
System.out.println("Sun " + "Mon " + "Tue " + "Wed " + "Thu " + "Fri " + "Sat ");
If you need a new line after printf, write %n
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!