Hi,

thanks for the welcome. I hope you can help me with ,y java pursuit.

I am trying to create a class Date which will eventually contains a single method called showMonth() which will display a calendar for a particular month in the following format (
JanuarySMTWTFS 12345678910111213141516171819202122232425262728293031
I am trying to pass the following parameters
String monthName; // e.g. January
int daysInMonth; // e.g. 31
int dayOfWeek; // day of the week (1-7)
// that the month starts
// assuming that Sunday is 1

To display the above I have a runIt() method in the DateDemo class which asks the user for (monthName, numOfDays, startDay) and then calls showMonth(monthName, numOfDays, startDay)

e.g. “January”, 31, 3.

But at the moment all I am getting is numbers 1 to 49 (7 * 7 = 7 rows by 7 columns) in a 7 * 7 block.
S M T W T F S
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 30 31 32 33 34 35
36 37 38 39 40 41 42
43 44 45 46 47 48 49

Eventually I will use the code below to create the method.

int count =1;


for (int row = 1; row <= 7; row++)
{
for (int col = 1; col <= 7; col++)
{
System.out.print(count + "\t");
count++;
}
System.out.println();
}
}
can you point me in the right direction please

I have got

January
S    M    T    W    T    F    S
                              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  30 
31

using the code

System.out.println("\t\t\tJanuary");//writes to the screen the answer
String heading = "S\tM\tT\tW\tT\tF\tS";
System.out.println(heading);//writes to the screen the answer
/*
* This just writes what ever in a 7 * 7 block
*/int count = -5;


for (int row = 1; row <= 7; row++)
{for (int col = 1; col <= 7; col++)
{if (count <0)
{
System.out.print(""+"\t");
count++;
}else if (count <31)
{
count++;
System.out.print(count + "\t");
}else if (count == 31){
System.out.print("" + "\t");
}



}
System.out.println();
}
}

all i have to do know is enter this into a class...... any help would be nice please

cheers peeps from daniweb

I've got an idea :

for (int i = 1; i <= nrOfDays; i++) {
if (i < startDay) System.out.print(" "); // 3 spaces
else System.out.print(""+(i < 10 ? " " : "") + i);
if (i % 7 == 0) System.out.println();
}

I didn't try it, but it should be OK,

peter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.