You are on page 1of 17

publ

i
ccl
assCer
ti
fi
cat
eDemo1{

publ
i
cstati
cvoidmain(Str
ing[
]ar
gs){
//TODOAut o-
generatedmethodst
ub
Cert
if
icat
e1certi
fi
cate1=newCerti
fi
cat
e1(
60,
"cnexir
k",
"cbnifms",77);
Cert
if
icat
e1certi
fi
cate2=newCerti
fi
cat
e1(
45,
"gphspvq","
pqjbhmz" ,62);
Cert
if
icat
e1certi
fi
cate3=newCerti
fi
cat
e1(
41,
"nfpxsmp","vi
mi opu",
89);
Cert
if
icat
e1certi
fi
cate4=newCerti
fi
cat
e1(
95,
"i
onouca","bsbknpx" ,
38);
Cert
if
icat
e1certi
fi
cate5=newCerti
fi
cat
e1(
39,
"yhzraf
u",
"itnbskb",
44) ;

Cer
ti
fi
cat
e1[
]obj
Arr
ay={
cer
ti
fi
cat
e1,
cer
ti
fi
cat
e2,
cer
ti
fi
cat
e3,
cer
ti
fi
cat
e4,
cer
ti
fi
cat
e5}
;

Cer
ti
fi
cat
e1[
]obj
Resul
tAr
ray
1=get
EvenPosi
ti
onCer
ti
fi
cat
e(obj
Arr
ay)
;

i
f(
objResul
tArr
ay1==nul
l)
{
System.out
.pr
int
ln(
"Out
putaf
terf
ir
stoper
ati
onisnull
.")
;
}el
se{
System.out
.pr
int
ln(
"Di
spl
ayi
ngcontent
sofresul
tar
ray:"
);

for
(Cert
ifi
cate1certi
fi
cate:
objResul
tArr
ay1)
{
Syst
em. out
.pri
ntl
n(cert
if
icat
e.getI
d()
+" " + cer
ti
fi
cat
e.get
Tit
le(
)+" " +
cer
ti
fi
cat
e.get
Date()
+""+cer t
if
icate.
getRank()
+"");
}

publ
i
cst ati
cCer tif
icat e1[
]getEv
enPositi
onCer
ti
fi
cat
e(Cer
ti
fi
cat
e1[
]obj
)
{
intn=((obj.
lengt h)/2)+1;
Certif
icate1[]obj 1=newCertif
icat
e1[
n];
intj
=0;
for(
inti=0;i<obj.length;i
++)
{
if(
i%2==0)
{
obj1[
j]=obj [
i]
;
j
++;
}
}

r
etur
nobj
1;
}
}

classCer tifi
cate1
{
privat
ei ntid,r
ank;
privateSt r
ingt i
tle,
date;
publ i
cCer tif
icate1(inti
d,St
ri
ngt
it
le,
Str
ingdat
e,i
ntr
ank)
{this.i
d=id;
this.ti
tl
e=titl
e;
this.date=dat e;
this.rank=rank;

i
ntgetId(
)
{
r
eturnid;
}
i
ntgetRank()
{
r
eturnrank;
}
Str
inggetTitl
e( )
{
r
eturntitl
e;
}
Str
inggetDat e()
{
r
eturndat e;
}
voi
dset I
d(i
nti d)
{
t
his.
id=id;
}

v
oidsetRank(
intrank){
thi
s.r
ank=r ank;
}

v
oidsetTi
tl
e(St
ri
ngti
tl
e){
thi
s.t
it
le=ti
tl
e;
}

v
oidsetDate(
Str
ingdat
e){
thi
s.dat
e=dat e;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
publ
icclassCerti
fi
cateDemo1{

publ
i
cstati
cvoidmain(Str
ing[
]ar
gs){
//TODOAut o-
generatedmethodst
ub
Cert
if
icat
e1certi
fi
cate1=newCerti
fi
cat
e1(
60,
"cnexir
k",
"cbnifms",77);
Cert
if
icat
e1certi
fi
cate2=newCerti
fi
cat
e1(
45,
"gphspvq","
pqjbhmz" ,62);
Cert
if
icat
e1certi
fi
cate3=newCerti
fi
cat
e1(
41,
"nfpxsmp","vi
mi opu",
89);
Cert
if
icat
e1certi
fi
cate4=newCerti
fi
cat
e1(
95,
"i
onouca","bsbknpx" ,
38);
Cert
if
icat
e1certi
fi
cate5=newCerti
fi
cat
e1(
39,
"yhzraf
u",
"itnbskb",
30) ;

Cer
ti
fi
cat
e1[
]obj
Arr
ay={
cer
ti
fi
cat
e1,
cer
ti
fi
cat
e2,
cer
ti
fi
cat
e3,
cer
ti
fi
cat
e4,
cer
ti
fi
cat
e5}
;

Cer
ti
fi
cat
e1[
]obj
Resul
tAr
ray
1=sear
chCer
ti
fi
cat
eBy
Rank(
obj
Arr
ay,
44)
;

i
f(
objResul
tArr
ay1.
length==0){
System.out
.pr
intl
n("Out
putafterf
ir
stoper
ati
onisnull
.")
;
}el
se{
System.out
.pr
intl
n("Di
spl
ayingcontent
sofresul
tar
ray:"
);

for
(Cert
ifi
cate1certi
fi
cate:
objResul
tArr
ay1)
{
Syst
em. out
.pri
ntl
n(cert
if
icat
e.getI
d()
+" " + cer
ti
fi
cat
e.get
Tit
le(
)+" " +
cer
ti
fi
cat
e.get
Date()
+""+cer t
if
icate.
getRank()
+"");
}

publ
i
cst
ati
cCer
ti
fi
cat
e1[
]sear
chCer
ti
fi
cat
eBy
Rank(
Cer
ti
fi
cat
e1[
]obj
,
intr
ank)
{

i
ntj
=0;
i
ntc=0;
f
or(
inti=0;i
<obj.
length;i
++)
{
intno=obj[
i]
.getRank()
;
if(
no==rank){
c++;
}
}

Cer
ti
fi
cat
e1[
]ar
r=newCer
ti
fi
cat
e1[
c];
f
or(i
nti=0;i
<obj.
length;i
++)
{
intno=obj[
i]
.getRank()
;
if(
no==rank)
{
arr[
j]
=obj[
i]
;
j++;
}
}
r
etur
nar r;
}

classCer tifi
cate1
{
privat
ei ntid,r
ank;
privateSt r
ingt i
tle,
date;
publ i
cCer tif
icate1(inti
d,St
ri
ngt
it
le,
Str
ingdat
e,i
ntr
ank)
{this.i
d=id;
this.ti
tl
e=titl
e;
this.date=dat e;
this.rank=rank;

i
ntgetId(
)
{
r
eturnid;
}
i
ntgetRank()
{
r
eturnrank;
}
Str
inggetTitl
e( )
{
r
eturntitl
e;
}
Str
inggetDat e()
{
r
eturndat e;
}
voi
dset I
d(i
nti d)
{
t
his.
id=id;
}
v
oidsetRank(
intrank){
thi
s.r
ank=r ank;
}

v
oidsetTi
tl
e(St
ri
ngti
tl
e){
thi
s.t
it
le=ti
tl
e;
}

v
oidsetDate(
Str
ingdat
e){
thi
s.dat
e=dat e;
}

.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub

Mai
l
Boxmail
box1=newMailBox(22,
"rsqhpiz",
"yjsy
mpz" );
Mai
l
Boxmail
box2=newMailBox(83,
"xwjrqnu",
" ahr
xtbb");
Mai
l
Boxmail
box3=newMailBox(47,
"zgesjsr"
,"cxnkctl
");
Mai
l
Boxmail
box4=newMailBox(66,
"xaosles",
"jvdrt
xf")
;
Mai
l
Boxmail
box5=newMailBox(1,
"yi
lxuua","
ycnejof")
;
Mai
l
Box[
]obj
Arr
ay={mail
box1,
mai l
box2,mai l
box3,mai l
box4,
mai
l
box5}
;
Mai
l
Boxmail
boxRes1=newMailBox(27,"
ffatwgo" ,
"dkxgai
d")
;

bool
eanresul
t=repl
aceMail
BoxBy
Id(
obj
Arr
ay,
mail
boxRes1);
Syst
em.out.
pri
ntl
n("
Outputf
orper
for
mingr
epl
aceonmailboxRes1i
s:"
+resul
t);

Sy
stem.
out
.pr
int
ln(
"Di
spl
ayi
ngcont
ent
sofar
ray
:")
;

for
(Mai
l
Boxmai l
box:obj
Array){
Syst
em.out
.pr
int
ln(
mai l
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()
+"");
}
System.out.
pri
ntl
n()
;

Mai
lBoxmail
boxRes2=newMai l
Box(
1,"
hqzmrfz"
,"
fcbudy
i")
;
r
esul
t=repl
aceMai
lBoxByI
d(obj
Arr
ay,mail
boxRes2);

Sy
stem.
out
.pr
int
ln(
"Out
putf
orper
for
mingr
epl
aceonmai
l
boxRes2i
s:"
+resul
t);

Sy
stem.
out
.pr
int
ln(
"Di
spl
ayi
ngcont
ent
sofar
ray
:")
;

for(
MailBoxmail
box11:
objAr
ray){
System.out
.pr
int
ln(
mail
box11.get
Id(
)+" " + mai
l
box11.
get
Name(
)+" " +
mai
l
box
11.getCr
eati
onDate(
)+""
);

}
}

publ
i
cst
ati
cbool
eanr
epl
aceMai
l
BoxBy
Id(
Mai
l
Box[
]obj
Arr
y,Mai
l
Boxobj
New)
{

f
or(i
nti
=0; i
<objArry
.length;i
++)
{
if
(objArr
y[i
].
getId()==obj
New.get
Id(
))
{
objArr
y[i
]=objNew;
ret
urntrue;
}
}
r
etur
nf al
se;

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creati
onDate;
publi
cMai lBox(i
ntid, St
ri
ngname, Str
ingcr
eat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creat
ionDate=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetI
d( i
ntid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publ
i
cSt ri
ngget Creati
onDate(){
ret
urncr eat
ionDat e;
}
publ
i
cv oidsetCreationDate(
Stri
ngcreat
ionDat
e){
thi
s.creati
onDat e=creati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub

Mail
Boxmailbox1=newMailBox(
22,"rsqhpiz",
"yjsy
mpz" )
;
Mail
Boxmailbox2=newMailBox(
83,"xwjrqnu",
" ahr
xtbb")
;
Mail
Boxmailbox3=newMailBox(
47,"zgesjsr"
,"cxnkctl
")
;
Mail
Boxmailbox4=newMailBox(
66,"xaosles",
"jvdrt
xf"
);
Mail
Boxmailbox5=newMailBox(
1,"yi
lxuua","
ycnejof")
;
Mail
Box[
]objArray
={ mai
l
box1,
mailbox2,mai l
box3,mailbox4,
mai
l
box5}
;
sor
tMai
l
BoxByI
d(obj
Array);

Sy
stem.
out
.pr
int
ln(
"Di
spl
ayi
ngcont
ent
sofar
ray
:")
;

for
(Mai l
Boxmailbox:
objAr
ray){
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}

publ
i
cst
ati
cvoi
dsor
tMai
l
BoxBy
Id(
Mai
l
Box[
]obj
Arr
y)
{

f
or(
inti
=0; i
<objArry
.length;i++)
{
for(
intj
=i+1;j
<obj Arry.
length;j++)
if
(objArr
y[i
].
getId()>obj
Ar ry
[j]
.getI
d()
)
{
MailBoxtemp=obj Arry[
i]
;
objArr
y[i
]=objArry[
j];
objArr
y[j
]=temp;

}
}

}
cl
assMailBox
{
pri
vateinti
d;
pri
vateStri
ngname,cr
eationDat
e;
publi
cMai l
Box(
inti
d,Str
ingname,St
ri
ngcr
eat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creat
ionDat
e=cr
eat
ionDat
e;
}
publ
i
cintget I
d(){
ret
urni d;
}
publ
i
cv oidsetId(i
ntid){
thi
s.i
d=i d;
}
publ
i
cSt ri
ngget Name( ){
ret
urnname;
}
publ
i
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publ
i
cSt ri
ngget CreationDate(){
ret
urncr eati
onDat e;
}
publ
i
cv oidsetCreationDat e(
Stri
ngcreat
ionDat
e){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub

Mail
Boxmailbox1=newMai l
Box(67,
"i
sy vzun",
"egyyxwz "
);
Mail
Boxmailbox2=newMai l
Box(74,
"xrxpxrr"
,"
bkmxnck" );
Mail
Boxmailbox3=newMai l
Box(12,
"xcromhc" ,
"sbndhax");
Mail
Boxmailbox4=newMai l
Box(22,
"j
lnyloj"
,"
ouy r
jyo"
);
Mail
Boxmailbox5=newMai l
Box(9,
"xyyhkuk",
"usqzuhu" )
;
Mail
Box[
]objArr
ay={mai
lbox1,mail
box2,mai l
box3,mailbox4,
mai
l
box5}
;
sor
tMail
BoxByName(obj
Array);

Sy
stem.
out
.pr
int
ln(
"Di
spl
ayi
ngcont
ent
sofar
ray
:")
;

for
(Mai l
Boxmailbox:
objAr
ray){
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}

publ
i
cst
ati
cvoi
dsor
tMai
l
BoxBy
Name(
Mai
l
Box[
]obj
Arr
y)
{

f
or(
inti
=0;i
<objAr
ry.
lengt
h;i++)
{
for
(i
ntj
=i+1;j
<objArr
y.l
engt
h;j
++)
i
f(
objAr
ry[
i]
.getName( )
.compareTo(
obj
Arr
y[j
].
get
Name(
))>0)
{
Mail
Boxt emp=objAr r
y[i
];
obj
Arry[i
]=objAr
ry[
j];
obj
Arry[j
]=temp;

}
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creationDate;
publi
cMai lBox(intid, Stri
ngname, Str
ingcreat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creati
onDat e=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetId(intid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publi
cSt ri
ngget Cr eationDate(){
ret
urncr eationDat e;
}
publi
cv oidsetCr eationDat e(
Stri
ngcreat
ionDate){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub

Mai
l
Boxmail
box1=newMai
lBox(
66,"xi
ibr
np" ,
"t
wqjgvl"
);
Mai
l
Boxmail
box2=newMai
lBox(
94,"wdgxzwr ",
"pvi
xi
ct")
;
Mai
l
Boxmail
box3=newMai
lBox(
40,"xhetnxe",
"wvtmcwk");
Mai
l
Boxmail
box4=newMai
lBox(
69,"abeshrf",
"mfdj
wqq");
Mai
l
Boxmail
box5=newMai
lBox(
92,"bhdeebj",
"oymobpe");
Mai
l
Box[
]obj
Arr
ay={mai
l
box1,
mailbox2,mailbox3,
mailbox4,
mai
l
box5}
;
sor
tMai
l
BoxBy
Creat
ionDat
e(obj
Arr
ay)
;

Sy
stem.
out
.pr
int
ln(
"Di
spl
ayi
ngcont
ent
sofar
ray
:")
;

for
(Mai l
Boxmailbox:
objAr
ray){
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}

publ
i
cst
ati
cvoi
dsor
tMai
l
BoxBy
Creat
ionDat
e(Mai
l
Box[
]obj
Arr
y)
{

f
or(
inti
=0; i
<objArry
.length;i++)
{
for(
intj
=i+1;j
<obj Arry.
length;j
++)
if
(objArr
y[i
].
getCr eat
ionDate().
compar
eTo(
obj
Arr
y[j
].
get
Creat
ionDat
e()
)>0)
{
MailBoxtemp=obj Arry
[i]
;
objArr
y[i
]=obj Ar
ry[
j];
objArr
y[j
]=temp;

}
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creationDate;
publi
cMai lBox(intid, Stri
ngname, Str
ingcreat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creati
onDat e=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetId(intid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publi
cSt ri
ngget Cr eationDate(){
ret
urncr eationDat e;
}
publi
cv oidsetCr eationDat e(
Stri
ngcreat
ionDate){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub

Mai
l
Boxmai
l
box1=newMai
l
Box(
30,
"l
satkwk","ckbkape" )
;
Mai
l
Boxmai
l
box2=newMai
l
Box(
38,
"j
bqeszs","tzxuuhz "
);
Mai
l
Boxmai
l
box3=newMai
l
Box(
22,
"rpat
wey "
,"qkkj exb"
);
Mai
l
Boxmai
l
box4=newMai
l
Box(
80,
"pfci
raa",
"unaf xwg");
Mai
l
Boxmai
l
box5=newMai
l
Box(
39,
"ghohpje"
,"fglxdpa");

Mai
l
Box[
]obj
Arr
ay={
mai
l
box1,
mai
l
box2,
mai
l
box3,
mai
l
box4,
mai
l
box5}
;

MailBox[]objResul
tArr
ay1=searchMail
BoxByName(objArr
ay,
"hxr
kvy
u")
;
i
f(objResult
Ar r
ay1==nul
l)
{
System.out.pri
ntl
n("
Outputaf
terfi
rstsear
chisnull
.")
;
}el
se{
System.out.pri
ntl
n("
Displ
ayi
ngcont ent
sofresul
tarr
ay:")
;

for
(Mai l
Boxmailbox:
objResul
tArr
ay1)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}

MailBox[]objResul
tArr
ay2=searchMail
BoxByName(objArr
ay,
"lsat
kwk"
);
i
f(objResult
Ar r
ay2==nul
l)
{
System.out.pri
ntl
n("
Outputaf
terfi
rstsear
chisnull
.")
;
}el
se{
System.out.pri
ntl
n("
Displ
ayi
ngcont ent
sofresul
tarr
ay:")
;

for
(Mai l
Boxmailbox:
objResul
tArr
ay2)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}
}

publ
i
cst ati
cMai l
Box[]sear
chMai l
BoxByName(
Mai
l
Box[
]obj
Arr
y,St
ri
ngname)
{
intc=0;
for(i
nti=0;i
<objArr
y.l
ength;i
++)
{
Stri
ngnam=obj Ar
ry[
i]
.getName()
;
if(
nam. equal
s(name))
{c++;
}
}
i
ntj=0;
MailBox[
]arr=newMai l
Box[c]
;
f
or (
inti
=0;i<objArr
y.l
ength;i
++)
{
Stri
ngnam=obj Ar
ry[
i]
.getName(
);
i
f(nam.equals(name))
{
ar
r[j
]=objArr
y[i
];
j
++;
}
}

r
etur
nar
r;
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creationDate;
publi
cMai lBox(intid, Stri
ngname, Str
ingcreat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creati
onDat e=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetId(intid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publi
cSt ri
ngget Cr eationDate(){
ret
urncr eationDat e;
}
publi
cv oidsetCr eationDat e(
Stri
ngcreat
ionDate){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodst
ub
Mai
l
Boxmai
l
box1=newMai
l
Box(
93,
"hfyquem","xcl
zutr
");
Mai
l
Boxmai
l
box2=newMai
l
Box(
25,
"ajdl
ukm" ,
"hzeust
v");
Mai
l
Boxmai
l
box3=newMai
l
Box(
26,
"rsusdgf"
,"
upxpgwq" );
Mai
l
Boxmai
l
box4=newMai
l
Box(
37,
"kasysrr"
,"
rahcqck")
;
Mai
l
Boxmai
l
box5=newMai
l
Box(
39,
"fvhepzs",
"djkl
j
sd")
;

Mai
l
Box[
]obj
Arr
ay={
mai
l
box1,
mai
l
box2,
mai
l
box3,
mai
l
box4,
mai
l
box5}
;

MailBox[]objResul
tArr
ay1=searchMail
BoxByCreat
ionDat
e(obj
Arr
ay,
"jv
xfaua"
);
i
f(objResult
Ar r
ay1==nul
l)
{
System.out.pri
ntl
n("
Outputaf
terfi
rstsear
chisnull
.");
}el
se{
System.out.pri
ntl
n("
Displ
ayi
ngcont ent
sofresul
tarray
:")
;

for
(Mai l
Boxmailbox:
objResul
tArr
ay1)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}

MailBox[]objResul
tArr
ay2=searchMail
BoxByCreat
ionDat
e(obj
Arr
ay,
"rahcqck"
);
i
f(objResult
Ar r
ay2==nul
l)
{
System.out.pri
ntl
n("
Outputaf
terfi
rstsear
chisnull
.");
}el
se{
System.out.pri
ntl
n("
Displ
ayi
ngcont ent
sofresul
tarray
:")
;

for
(Mai l
Boxmailbox:
objResul
tArr
ay2)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}

publ
i
cst ati
cMai l
Box[]sear
chMai l
BoxByCr
eat
ionDat
e(Mai
l
Box[
]obj
Arr
y,St
ri
ngname)
{
intc=0;
for(i
nti=0;i
<objArr
y.l
ength;i
++)
{
Stri
ngnam=obj Ar
ry[
i]
.getCr
eati
onDat
e()
;
if(
nam. equal
s(name))
{c++;

}
}
i
ntj=0;
MailBox[
]arr=newMai l
Box[c]
;
f
or (
inti
=0;i
<obj Arr
y.l
ength;i
++)
{
Stri
ngnam=obj Ar
ry[
i]
.getCr
eati
onDat
e()
;
i
f(nam.equals(name))
{
ar
r[
j]=objArr
y[i
];
j
++;
}
}

r
etur
nar
r;
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creationDate;
publi
cMai lBox(intid, Stri
ngname, Str
ingcreat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creati
onDat e=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetId(intid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publi
cSt ri
ngget Cr eationDate(){
ret
urncr eationDat e;
}
publi
cv oidsetCr eationDat e(
Stri
ngcreat
ionDate){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodstub
Mail
Boxmail
box1=newMai l
Box(18,"
scfkfwm",
"vjl
hejv")
;
Mail
Boxmail
box2=newMai l
Box(44,"
vykwuqm" ,
"hxbgccj")
;
Mail
Boxmail
box3=newMai l
Box(77,"
ddwhwhg" ,"
eiqshsv")
;
Mail
Boxmail
box4=newMai l
Box(79,"
ctppqch"
,"
quy vfi
m" )
;
Mail
Boxmail
box5=newMai l
Box(9,
"fdoyxqc"
,"
vikysdr")
;

Mai
l
Box[
]obj
Arr
ay={
mai
l
box1,
mai
l
box2,
mai
l
box3,
mai
l
box4,
mai
l
box5}
;

Mai
l
Box[
]obj
Resul
tAr
ray
1=get
OddPosi
ti
onMai
l
Box(
obj
Arr
ay)
;
i
f(objResul
tArr
ay1==nul
l)
{
System.out.
pri
ntl
n("
Outputaf
terf
ir
stoper
ati
onisnull
.")
;
}el
se{
System.out.
pri
ntl
n("
Displ
ayi
ngcontent
sofresul
tar
ray:"
);

for
(Mai l
Boxmailbox:
objResul
tArr
ay1)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}

publ
i
cst at
icMai l
Box[]getOddPositi
onMai
l
Box(
Mai
l
Box[
]obj
Arr
y)
{
intj
=0;
intc=(objAr
ry.
length/2);
Mai l
Box[]ar
r=newMai l
Box[c]
;
for(
inti=0;i
<objArr
y .
length;
i++)
{

i
f(
i%2!
=0)
{
arr
[j
]=obj
Arr
y[i
];
j
++;
}
}

r
etur
nar
r;
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creati
onDate;
publi
cMai lBox(i
ntid, St
ri
ngname, Str
ingcr
eat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creat
ionDate=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetI
d( i
ntid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publ
i
cSt ri
ngget Creati
onDate(){
ret
urncr eat
ionDat e;
}
publ
i
cv oidsetCreationDate(
Stri
ngcreat
ionDat
e){
thi
s.creati
onDat e=creati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

publ
i
ccl
assMai
l
BoxDemo{

publ
i
cstat
icv
oidmain(Str
ing[
]ar
gs){
//TODOAuto-
generatedmethodstub
Mail
Boxmail
box1=newMai l
Box(7,
"vj
cml we","
szfol
wb");
Mail
Boxmail
box2=newMai l
Box(67,"
imcftaw","
jl
nzywo");
Mail
Boxmail
box3=newMai l
Box(26,"
lsckexs",
"l
yqonys"
);
Mail
Boxmail
box4=newMai l
Box(5,
"cbajxhj"
,"
rgwyxze")
;
Mail
Boxmail
box5=newMai l
Box(4,
"bxifpl
c",
"wevsaco")
;

Mai
l
Box[
]obj
Arr
ay={
mai
l
box1,
mai
l
box2,
mai
l
box3,
mai
l
box4,
mai
l
box5}
;

MailBox[]objResul
tArr
ay1=getEv
enPosi t
ionMail
Box(obj
Arr
ay)
;
i
f(objResult
Ar r
ay1==nul
l)
{
System.out.pri
ntl
n("
Outputaf
terf
irstoperati
onisnull
.")
;
}el
se{
System.out.pri
ntl
n("
Displ
ayi
ngcont ent
sofr esul
tar
ray:"
);

for
(Mai l
Boxmailbox:
objResul
tArr
ay1)
{
System.out.
pri
ntl
n(mail
box.get
Id(
)+" " + mai
l
box.
get
Name(
)+" " +
mai
l
box
.get
Cr eat
ionDat
e()+""
);
}
}
}

publ
i
cst at
icMai l
Box[]getEvenPositi
onMai
l
Box(
Mai
l
Box[
]obj
Arr
y)
{
intj
=0;
intc=(objAr
ry.
length/2)+1;
Mai l
Box[]ar
r=newMai l
Box[c]
;
for(
inti=0;i
<objArr
y .
length;
i++)
{

i
f(
i%2==0)
{
ar
r[
j]
=obj
Arr
y[i
];
j
++;
}
}
r
etur
nar
r;
}

}
cl
assMailBox
{
pri
vateintid;
pri
vateSt r
ingname, creationDate;
publi
cMai lBox(intid, Stri
ngname, Str
ingcreat
ionDat
e){
super();
thi
s.i
d=i d;
thi
s.name=name;
thi
s.creati
onDat e=cr eati
onDate;
}
publi
cintget I
d(){
ret
urni d;
}
publi
cv oidsetId(intid){
thi
s.i
d=i d;
}
publi
cSt ri
ngget Name( ){
ret
urnname;
}
publi
cv oidsetName( Stri
ngname){
thi
s.name=name;
}
publi
cSt ri
ngget Cr eationDate(){
ret
urncr eationDat e;
}
publi
cv oidsetCr eationDat e(
Stri
ngcreat
ionDate){
thi
s.creati
onDat e=cr eati
onDate;
}

}
.
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..
..

You might also like