Computer Science Canada Making a calendar program? |
Author: | jsnnyj [ Wed Mar 15, 2006 12:21 pm ] |
Post subject: | Making a calendar program? |
Hi, right now I need to make a program that you have to input the day that the first date of a month falls upon ( for example, Tuesday, Friday,etc) and then outputs the days of the month and the corresponding days. I thought this would be easy but now I'm stuck. I have a date[] array of 31 elements, but how can I don't quite get how to assign the days for the dates, because it doesn't have to start from 1 to 7. Any help is greatly appreciated, thx! |
Author: | Justin_ [ Wed Mar 15, 2006 2:01 pm ] |
Post subject: | |
Does this program have to address there are varying amounts of days in each month? Try making a class to include information for each day, like name of day and number, then make an array of them. Then find an efficient way to initialize them with all the information. Then design a method you can call in a loop for all the objects in the array that will say what their information is. |
Author: | jsnnyj [ Wed Mar 15, 2006 2:30 pm ] |
Post subject: | |
Justin_ wrote: Does this program have to address there are varying amounts of days in each month?
Try making a class to include information for each day, like name of day and number, then make an array of them. Then find an efficient way to initialize them with all the information. Then design a method you can call in a loop for all the objects in the array that will say what their information is. No, it should assume that the month has 31 days. The parts I don't get is how to initialize it and output the information. |
Author: | Justin_ [ Wed Mar 15, 2006 2:45 pm ] | ||
Post subject: | |||
if it is always 31 days than you could make a day array that holds all the days of the week. (monday, tues etc..) then make an array of 31 Days. Day being the name of your class. Then make its day and number private, make a method called editDay(string day) and make the method set day to whatever day is. Same sort of thing for number. Then to initialize it, in your main function you'd write
the 1 % 7 incase you don't know what that is, dont' worry about it, just make sure you day array hold the seven days of the week [monday, tuesday etc..] and you can use i % 7 to keep the bounds within that array even though i gets much larger. hint: since the user inputs the first day, you'll have to make the day array begin initializing on the day the user inputs. |
Author: | Justin_ [ Wed Mar 15, 2006 4:06 pm ] | ||
Post subject: | |||
Here, this should give you a good idea of what I am talking about. Remember this is just one way to do it, and I hope this is what you wanted. If not, than I misunderstood the guidelines.
|
Author: | jsnnyj [ Wed Mar 15, 2006 7:57 pm ] |
Post subject: | |
thank you for the help ![]() |
Author: | Martin [ Thu Mar 16, 2006 3:40 am ] | ||||
Post subject: | |||||
Just for fun, in Ruby
The enum simply defines SUNDAY as 0, MONDAY as 1, TUESDAY as 2, etc. And with colour!
|
Author: | wtd [ Thu Mar 16, 2006 12:04 pm ] | ||||
Post subject: | |||||
Martin, this:
Is better written as:
|
Author: | wtd [ Thu Mar 16, 2006 12:41 pm ] | ||
Post subject: | |||
|
Author: | McKenzie [ Thu Mar 16, 2006 11:55 pm ] |
Post subject: | |
I hate to point out the obvious, but "Java Help" should result in Java code. |
Author: | wtd [ Thu Mar 16, 2006 11:58 pm ] |
Post subject: | |
Talk to Martin. ![]() Once it was said, though, I thought it worthwhile to have the best code possible available. Ruby's pretty straightforward, and expressive. I don't think it'd be too hard to take that code and translate it to Java. |