java技術博客
jsp博客
BlogJava
首頁
新隨筆
聯系
聚合
管理
數據加載中……
MuilInterfaceTest.java
/** */
/**
*通過這個程序,我們要測試接口的多重實現,并學習對象比較方法的實現
*/
import
java.util.Arrays
public
class
MuilInterfaceTest
{
public
static
void
main(String[] args)
{
Student[] staff
=
new
student[
3
];
staff[
0
]
=
new
Student(
"
tom
"
,
"
20031020
"
);
staff[
1
]
=
new
Student(
"
jack
"
,
"
20031022
"
);
staff[
2
]
=
new
Student(
"
rose
"
,
"
20021023
"
);
Arrays.sort(staff);
for
(
int
i
=
0
;i
<
staff.length;i
++
)
{
System.out.println((Student)staff[i]);
}
}
}
/**/
/*
*學生類,包括學生的基本信息,實現了Person與Comparable接口
*/
class
Student
implements
Person, Comparable
{
private
String strName
=
""
;
//
學生姓名
private
String strNumber
=
""
;
//
學號
private
String strSex
=
""
;
//
性別
private
String strBirthday
=
""
;
//
出生年月
private
String strSpeciality
=
""
;
//
專業
private
String strAddress
=
""
;
//
地址
public
Student(String name, String number)
{
strName
=
name;
strNumber
=
number;
}
public
int
compareTo(Object otherObject)
{
Student other
=
(Student)otherObject;
int
otherNumber
=
Integer.parseInt(other.strNumber);
int
thisNumber
=
Integer.parseInt(
this
.strNumber);
if
(thisNumber
>
otherNumber)
return
1
;
else
if
(thisNubmer
==
otherNumber)
return
0
;
else
return
-
1
;
}
public
String getName()
{
return
strName;
}
public
String getStudentNumber()
{
return
strNumber;
}
public
void
setStudentSex(String sex)
{
strSex
=
sex;
}
public
String getSex()
{
return
strSex;
}
public
String getBirthday()
{
return
strBirthday;
}
public
void
setStudentBirthday(String birthday)
{
strBirthday
=
birthday;
}
public
String getStudentSpeciality()
{
return
strSpeciality;
}
public
void
setStudentSpeciality(String speciality)
{
strSpeciality
=
speciality;
}
public
String getAddress()
{
return
strAddress;
}
public
void
setAddress(String address)
{
strAddress
=
address;
}
public
String toString()
{
String information
=
"
student name=
"
+
strName
+
"
student numbeer=
"
+
strNumber;
if
(
!
strSex.equals(
""
))
information
+=
"
,sex=
"
+
strSex;
if
(
!
strBirthday.equals(
""
))
information
+=
"
,Birthday=
"
+
strBirthday;
if
(
!
strSpeciality.equals(
""
))
information
+=
"
,專業=
"
+
strSpeciality;
if
(
!
strAddress.equals(
""
))
information
+=
"
,address=
"
+
strAddress;
return
information;}
}
posted on 2008-10-23 15:02
郭興華
閱讀(125)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 郭興華
<
2008年10月
>
日
一
二
三
四
五
六
28
29
30
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
1
2
3
4
5
6
7
8
統計
隨筆 - 84
文章 - 1
評論 - 2
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
java每日練習代碼
(rss)
TESTARRAY(6)
(rss)
事件模型與事件處理
(rss)
隨筆檔案
2009年1月 (2)
2008年11月 (14)
2008年10月 (68)
文章檔案
2008年10月 (1)
搜索
最新評論
1.?re: jsp讀取*.TXT
請問 retstr是什么數據類型?String?好像不行哦
--jsp
2.?re: StudentTest1.java
看不懂你的意思,代碼沒有縮進,看著很不習慣那。
--楊愛友
閱讀排行榜
1.?java中的treemap(4604)
2.?JDBC連接SQLSERVER(1822)
3.?判斷一個一個路徑是否是目錄(1085)
4.?jsp讀取*.TXT(764)
5.?java代理模式(727)
評論排行榜
1.?StudentTest1.java(1)
2.?jsp讀取*.TXT(1)
3.?java1.5注解(二)(0)
4.?java1.5注解(一)(0)
5.?jsp中使用類(0)
主站蜘蛛池模板:
罗城
|
德格县
|
夏津县
|
防城港市
|
武强县
|
融水
|
巴青县
|
徐州市
|
津市市
|
通州区
|
息烽县
|
福州市
|
安乡县
|
子长县
|
扎赉特旗
|
定西市
|
武冈市
|
宜州市
|
沧州市
|
南和县
|
林西县
|
天全县
|
余干县
|
特克斯县
|
东乌珠穆沁旗
|
德兴市
|
玛多县
|
峨眉山市
|
长沙市
|
贵港市
|
扎兰屯市
|
保德县
|
屏东市
|
孟州市
|
通道
|
江华
|
屯门区
|
彭阳县
|
绥滨县
|
嵊泗县
|
湘潭县
|