Win a copy of Spring in Action (5th edition) this week in the Spring 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
 
Saloon Keeper
Posts: 5144
54
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: 61727
193
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!