资源描述
实验报告
课程名称:java
班级:
实验成绩:
指导教师:
姓名:
实验项目名称:date
学号:
上机实践日期:
实验项目编号:
组号:
上机实践时间: 学时
一、 设计和编码
.主要代码段说明(附代码):
class MyDate {
private int year;
private int month;
private int day;
public MyDate(int day, int month, int year){
this.day = day;
this.month = month;
this.year = year;
}
public int getyear(){
return this.year;
}
public void setyear(int year){
this.year = year>0?year:0;
}
public int getmonth(){
return this.month;
}
public void setmonth(int month){
if(this.year>0)
if(month>=1 && month<= 12)
this.month=month;
}
public int getday(){
return this.day;
}
public int setday(int x){
switch(x){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 2:{
if((year%400==0)||(year%100!=0&&year%4==0))
return 29;
else
return 28;
}
default:
return 30;
}
}
public void print(){
System.out.println("MyDate: " + day + "-" + month + "-" + year);
}
public void prints(){
System.out.println("YourDate:"+day+"-"+month+"-"+year);
}
}
public class Date{
public static void main(String[] args){
int day=7;int yourday=7;
int month=7;int yourmonth=7;
int year=1990;int youryear=1990;
MyDate my_birth=new MyDate(day,month,year);
my_birth.setday(day);
my_birth.setmonth(month);
my_birth.setyear(year);
MyDate your_birth=new MyDate(yourday,yourmonth,youryear);
your_birth.setday(yourday);
your_birth.setmonth(yourmonth);
your_birth.setyear(youryear);
my_birth.print();
your_birth.prints();
}
}
二、运行结果及分析
运行结果:
展开阅读全文