sid's
Would you like to react to this message? Create an account in a few clicks or log in to continue.

sid's

OPen Discussion
 
HomePortalSearchLatest imagesRegisterLog in

 

 HELP~!

Go down 
2 posters
AuthorMessage
link_koza




Posts : 1
Join date : 2007-08-25

HELP~! Empty
PostSubject: HELP~!   HELP~! Icon_minitimeSat Aug 25, 2007 7:45 pm

hey kak,

i need help for the calendar assignment...i mean...i dunno how to start...the example u gave ... didn't clear up much stuffs...cuz most of it we haven't learn...and...i found this example from the net where the codes are..

import java.util.*;
import java.text.*;


public class MonthView {

/** List names of the month */
public final static String[] months = {
"January" , "February" , "March",
"April" , "May" , "June",
"July" , "August" , "September",
"October" , "November" , "December"
};


/** List the days in each month */
public final static int dom[] = {
31, 28, 31, /* jan, feb, mar */
30, 31, 30, /* apr, may, jun */
31, 31, 30, /* jul, aug, sep */
31, 30, 31 /* oct, nov, dec */
};


/**
* Helper utility used to print
* a String to STDOUT.
* @param s String that will be printed to STDOUT.
*/
private void printMonth(int mm, int yy) {

// The number of days to leave blank at
// the start of this month.
int leadSpaces = 0;

System.out.println();
System.out.println(" " + months[mm] + " " + yy);

if (mm < 0 || mm > 11) {
throw new IllegalArgumentException(
"Month " + mm + " bad, must be 0-11");
}

GregorianCalendar cal = new GregorianCalendar(yy, mm, 1);

System.out.println("Su Mo Tu We Th Fr Sa");

// Compute how much to leave before before the first day of the month.
// getDay() returns 0 for Sunday.
leadSpaces = cal.get(Calendar.DAY_OF_WEEK)-1;

int daysInMonth = dom[mm];

if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) {
++daysInMonth;
}

// Blank out the labels before 1st day of the month
for (int i = 0; i < leadSpaces; i++) {
System.out.print(" ");
}

for (int i = 1; i <= daysInMonth; i++) {

// This "if" statement is simpler than messing with NumberFormat
if (i<=9) {
System.out.print(" ");
}
System.out.print(i);

if ((leadSpaces + i) % 7 == 0) { // Wrap if EOL
System.out.println();
} else {
System.out.print(" ");
}

}
System.out.println();
}



/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {

int month, year;

MonthView mv = new MonthView();

if (args.length == 2) {
mv.printMonth(Integer.parseInt(args[0])-1, Integer.parseInt(args[1]));
} else {
Calendar today = Calendar.getInstance();
mv.printMonth(today.get(Calendar.MONTH), today.get(Calendar.YEAR));
}

}

}

when i tried to compile

HELP~! Quest210

when i tried running it comes with results

HELP~! Quest110


so my question is...

1) how do i start? any better tips?

2) must the results be in JOptionPane based or just in dos?
Back to top Go down
Admin
Admin



Posts : 50
Join date : 2007-08-10
Age : 44
Location : Kuala Lumpur

HELP~! Empty
PostSubject: Re: HELP~!   HELP~! Icon_minitimeTue Aug 28, 2007 11:37 am

link_koza wrote:
hey kak,

i need help for the calendar assignment...i mean...i dunno how to start...the example u gave ... didn't clear up much stuffs...cuz most of it we haven't learn...and...i found this example from the net where the codes are..

import java.util.*;
import java.text.*;


public class MonthView {

/** List names of the month */
public final static String[] months = {
"January" , "February" , "March",
"April" , "May" , "June",
"July" , "August" , "September",
"October" , "November" , "December"
};


/** List the days in each month */
public final static int dom[] = {
31, 28, 31, /* jan, feb, mar */
30, 31, 30, /* apr, may, jun */
31, 31, 30, /* jul, aug, sep */
31, 30, 31 /* oct, nov, dec */
};


/**
* Helper utility used to print
* a String to STDOUT.
* @param s String that will be printed to STDOUT.
*/
private void printMonth(int mm, int yy) {

// The number of days to leave blank at
// the start of this month.
int leadSpaces = 0;

System.out.println();
System.out.println(" " + months[mm] + " " + yy);

if (mm < 0 || mm > 11) {
throw new IllegalArgumentException(
"Month " + mm + " bad, must be 0-11");
}

GregorianCalendar cal = new GregorianCalendar(yy, mm, 1);

System.out.println("Su Mo Tu We Th Fr Sa");

// Compute how much to leave before before the first day of the month.
// getDay() returns 0 for Sunday.
leadSpaces = cal.get(Calendar.DAY_OF_WEEK)-1;

int daysInMonth = dom[mm];

if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) {
++daysInMonth;
}

// Blank out the labels before 1st day of the month
for (int i = 0; i < leadSpaces; i++) {
System.out.print(" ");
}

for (int i = 1; i <= daysInMonth; i++) {

// This "if" statement is simpler than messing with NumberFormat
if (i<=9) {
System.out.print(" ");
}
System.out.print(i);

if ((leadSpaces + i) % 7 == 0) { // Wrap if EOL
System.out.println();
} else {
System.out.print(" ");
}

}
System.out.println();
}



/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {

int month, year;

MonthView mv = new MonthView();

if (args.length == 2) {
mv.printMonth(Integer.parseInt(args[0])-1, Integer.parseInt(args[1]));
} else {
Calendar today = Calendar.getInstance();
mv.printMonth(today.get(Calendar.MONTH), today.get(Calendar.YEAR));
}

}

}

when i tried to compile

HELP~! Quest210

when i tried running it comes with results

HELP~! Quest110


so my question is...

1) how do i start? any better tips?

2) must the results be in JOptionPane based or just in dos?


ok, anyway good effort from you to try any related resources. I think from the question given, I believe that the program should asked the user to enter day of de month n year, then de program will display the calendar for the whole year. This is what I'm thinking. But the question is from ur lecturer, so u should clarify with him about the output that he wanted.

It's ok to display de output using DOS or JOptionPane.

try to figure out how to ask the user to enter the date using JOptionPane rather than just display the comp. date.

'bout the error, u need to declare the variables first. Gud luck!!
Back to top Go down
https://sidnazuha.board-directory.net
 
HELP~!
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
sid's :: TEACHING MATERIAL :: UPM-SAK3100-
Jump to: