Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 25th, 2003, 08:16 AM
2old2learn 2old2learn is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 2old2learn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Dates missing?

I am taking a beginning java class and I did a search on the web for calendar projects and I found this one. This code is suppose to print out a calendar for a month and year that's input by a user. The code prints out the month and array of days of the week but it will not print out the dates of the month.

Would someone be able to tell be why the program scrolls down after the days of the week row instead of printing out the dates 1, 2, 3, etc.? How do I get the dates of the month to show up.

Thank you for your patience and assistance.


PHP Code:
public class Calendar
{
public static 
void main(String[] args)
{
int year 0;

//Determine if it is a leap year
boolean isLeapYear true;
if (
isLeapYear)
year=year+1;


int total=0;
int startDay;
int month;


//array for number of days in each month
int DaysEachMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};

//array for corresponding days
String NameofMonth[]={"January","February","March","April","May",
"June","July","August","September","October",
"November","December"};

//ask user to enter year
System.out.println("Enter a full year:");
year SavitchIn.readLineInt();

if(
year<1800)
System.out.println("Year out of range!");
System.exit(0);

//ask user to enter month 
System.out.println("Enter a month in a form of a "
"number between 1-12:");
month SavitchIn.readLineInt();

if(
isLeapYear==true)
DaysEachMonth[1]=29;

//Get the total days from 1800 to year -1
for (int i=1800;i<year;i++)
{
if(
isLeapYear==true)
total=total+366;
else
total=total+365;
}
//Add days from Jan to the month prior to the
//calendar month
for (int i=1;i<month;i++)
total=total+DaysEachMonth[(i-1)];

startDay=(total+3)%7;

//Print the month title, i.e. May, 1999
System.out.println(" "+(month)+","+year);
System.out.println("----------------------------");
System.out.println("Sun Mon Tue Wed Thur Fri Sat");

//Determine if it is a leap year
if ((year 400 == 0)||((year == 0)&&(year 100 != 0)))

//Print month body
//Pad space before the first day of the month
for (int i=0i<startDay;i++)
{
System.out.println("");
}

for(
int i=1;i<=DaysEachMonth[month-1];i++)
{
if ((
startDay) % == 0)
System.out.println();

System.out.println();
}

}


Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Dates missing?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway