?? person.java
字號:
/**
文件:Person.java
說明:描述人的類文件
**/
import java.util.*;
import java.text.*;
/* 描述人的類 */
public class Person{
//身份證號
public String ID;
//姓名
public String name;
//性別
public String sex;
//出生年月
public Date brithDate;
//構造方法
public Person(String IID, String Iname, String Isex, Date IbrithDate)
{
this.ID = IID;
this.name = Iname;
this.sex = Isex;
this.brithDate = IbrithDate;
}
//獲得身份證號
public String getID()
{
return ID;
}
public String getSex()
{
return sex;
}
//獲得姓名
public String getName()
{
return name;
}
//獲得出生日期
public Date getBrithDate()
{
return brithDate;
}
// 計算當前年齡
public int getAge()
{
// 獲取當前年份
Calendar now = Calendar.getInstance();
int currentyear = now.get(Calendar.YEAR);
// 獲取出生年份
SimpleDateFormat fmt = new SimpleDateFormat("yyyy");
int brithyear = Integer.parseInt(fmt.format(brithDate));
return (currentyear - brithyear + 1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -