Item

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

I

tem.
jav
a

packagecom;

publ
iccl
assItem {
pri
vateintitemI d;
pri
vatedoubl epr ice;
pri
vateSt r
ingi temName;
pri
vateSt r
ingst atus;
publi
cItem( inti temId, doublepr i
ce,St
ri
ngi
temName,
Str
ingst
atus){
super ();
this.
itemI d=i temI d;
this.
pr ice=pr i
ce;
this.
itemName=i temName;
this.
st atus=st atus;
}
publi
cintget ItemI d(
){
returni temI d;
}
publi
cvoi dset ItemI d(i
nti temId){
this.
itemI d=i temI d;
}
publi
cdoubl eget Pri
ce( ){
returnpr ice;
}
publi
cvoi dset Pr ice(doubl epri
ce){
this.
pr ice=pr i
ce;
}
publi
cSt ri
ngget ItemName( ){
returni temName;
}
publi
cvoi dset ItemName( St
ri
ngi t
emName){
this.
itemName=i temName;
}
publi
cSt ri
ngget St at
us( ){
returnst atus;
}
publi
cvoi dset St atus(St r
ingstatus){
this.
st atus=st atus;
}

I
temDemo.
jav
a

packagecom;
publ
iccl
assItemDemo{
stat
icintcount
=0;
publi
cstati
cintget
It
emSt
atusCount
(I
tem[
]it
ems,
Str
ingst
at){

f
or(
It
em i
t:
it
ems){
if
(i
t.
get
Status(
).equal
sIgnor
eCase(
stat
)){
count++;
}
}

r
et ncount
ur ;
}

publ
icst
ati
cIt
em get
Avl
blCost
lyI
tem (
It
em[
]it
ems){

i
ntk=0;
I
tem[]i
t=newI t
em[ count];
f
or(I
tem ie:
it
ems){
i
f(i
e.getStat us().
equalsIgnoreCase(
"Avai
l
abl
e")
){
i
t[k]=ie;
k++;
}
}
f
or(i
nti=0;i
<it.
lengt h;i
++){
f
or(i
ntj =i+1; j
<it
.l
ength-1;j++)
{
i
f(items[i]
.getPrice()
<it
ems[j
].
get
Pri
ce(
)){
It
em t emp=i t
[i
];
i
t[i
]=it[j
];
i
t[j
]=temp;
}
}
}

r
etur
nit
[0]
;

publi
cstaticv oi
dmai n( Str
ing[]args){
//TODOAut o-gener atedmet hodst ub
I
tem[ ]it
ems=newI tem[ 5];
i
tems[ 0]=newIt em(1,45.0,"Noodl es",
"AVAI LABLE");
i
tems[ 1]=newIt em(2,125.0,"Pizza","
NOTAVAI LABLE")
;
i
tems[ 2]=newIt em(3,150.0,"MEALS" ,
"AVAI LABLE");
i
tems[ 3]=newIt em(4,175.0,"Sweet ",
"NOTAVAI LABLE"
);
i
tems[ 4]=newIt em(5,105.0,"Bur ger"
,"AVAILABLE" );
Str
ingst at="
Av ail
able";
System. out.
pri
nt l
n("No.ofi temsi n"+stat+"
st
atus:
"+ItemDemo. get I
temStat usCount (
items, stat)
);
I
tem ci t
em=I t
emDemo. getAv l
blCost l
y I
tem( i
tems);
System. out.
pri
nt l
n("Avail
abl eitem wi thhighestcostis"+ci
tem.
get
It
emName(
)+"wi
th
pr
ice"+cit
em. getPr
ice());
}
}

You might also like