(求助)JAVA编写类与类的测试程序

来源:百度知道 编辑:UC知道 时间:2024/05/15 08:42:37
请各位大大帮忙解决下面2个编程问题..都是要用JAVA编写的

(1)编写DateUtil类,该类包含:
成员变量:
year:整型public变量,用于表示年份;
month:整型public变量,用于表示月份;
int day:整型public变量,用于表示天数;
isLeapYear:布尔型private变量,用于表示是否为闰年.初始值为false
构造器方法:
DateUtil(int year,int month):用于初始化year变量和month变量
成员方法:
public boolean isLeapYear();用于判断年份是否为闰年
public int getMonthDays();用于计算并取得该月的天数

(2)编写DateUtil类的测试程序,判断XXXX年XX月有多少天,并输出如下格式的信息:

XXXX年为闰年(或平年)
XX月有XX天

--------------------------DateUtil类
/**
* @author 王炳焱
* 创建日期:2007-5-21
* 项目名称:te
* 文件名称:DateUtil
*/
package test0521;

/**
* @author Administrator
*
*/
public class DateUtil {
public int year;// 用于表示年份

public int month;// 用于表示月份

public int day;// 用于表示天数

private boolean isLeapYear = false;// 用于表示是否为闰年.初始值为false

DateUtil() {
}

DateUtil(int year, int month) {// 用于初始化year变量和month变量
this.year = year;
this.month = month;
}

public boolean isLeapYear() {// 用于判断年份是否为闰年
this.isLeapYear = (this.year % 4 == 0 & this.year % 100 != 0)
|| (this.year % 400 == 0);//闰年条件
return this.isLeapYear;
}

public int getMonthDays() {// 用于计算并取得该月的天数
int[] bigMonth = { 1, 3, 5, 7, 8, 10, 12 };//31天的月份
for (int i = 0; i < bigMonth.length; i++) {
if (this.month == bigMonth