You are on page 1of 3

Or

der
.j
ava
packagecom;

publ
iccl
assOr der{
pri
vateintorder I
d;
pri
vateSt r
ingi temName;
pri
vateSt r
ingcat egor y;
pri
vatedoubl epr ice;
pri
vatedoubl ei nsur anceAmount ;
publi
cOr der(i
ntor der I
d,Stringit
emName, Str
ingcategor
y,doubl
epr
ice,
doubl
einsur
anceAmount
)
{
super ();
this.
or der Id=or derId;
this.
itemName=i temName;
this.
cat egor y=cat egory
;
this.
pr i
ce=pr i
ce;
this.
insur anceAmount=i nsuranceAmount ;
}
publi
cintget Or der Id(){
retur
nor der Id;
}
publi
cv oidset Or der Id(i
ntor derI
d){
this.
or der Id=or derId;
}
publi
cSt ri
ngget ItemName( ){
retur
ni temName;
}
publi
cv oidset ItemName( Stri
ngitemName){
this.
itemName=i temName;
}
publi
cSt ri
ngget Cat egor y(){
retur
ncat egor y;
}
publi
cv oidset Cat egor y
(Stringcategory){
this.
cat egor y=cat egory
;
}
publi
cdoubl eget Pr ice(){
retur
npr i
ce;
}
publi
cv oidset Pr i
ce( doubl epr i
ce){
this.
pr i
ce=pr i
ce;
}
publi
cdoubl eget Insur anceAmount (){
retur
ni nsur anceAmount ;
}
publi
cv oidset Insur anceAmount (
doubleinsuranceAmount){
this.
insur anceAmount=i nsuranceAmount ;
}

Or
der
Demo.
jav
a
packagecom;

publ
iccl
assOr derDemo{
stat
icdoubl esum1=0. 0;
stat
icdoubl esum2=0. 0;
publi
cstaticdoubl ecalculat
eTotal
Pr i
ce(
Or der[]o){
for(Orderod:o){
i
f(od.
getCategory(
).
equalsIgnor eCase("Car")){
doubleon_road_price=od. getPri
ce( )+od.
getI
nsuranceAmount(
)+
((
od.
getPri
ce()
/100) *7);
sum1=sum1+on_ road_price;
}
i
f(od.getCat
egory()
.equalsIgnoreCase( "
Bike")){
doubleon_road_price1=od. getPrice()+od.
getI
nsuranceAmount(
)+
((
od.
getPri
ce()
/100) *10);
sum2=sum2+on_ road_price1;
}
}
doubl eresul=sum1+sum2;
t
returnresult;
}

publ
icst
aticOrder[]f
indOrder
By Categor
y(Order
[]or
,St
ri
ngs){
i
ntcount=0;
for
(Orderoe:or){
i
f(oe.get
Category()
.equal
sIgnor
eCase(s)
){
count++;
}
}
i
nti=0;
Order
[]order=newOr der[
count];
for
(Orderop:or){
i
f(op.get
Category()
.equal
sIgnor
eCase(s)
){
order
[i]
=op;
i
++;
}
}
ret
urnorder ;

publ
icst
aticv oidmai n(Str
ing[]ar
gs){
//TODOAut o- generatedmethodstub
Order[]orderList=newOr der
[5]
;
orderList[
0]=newOr der(
1234,"
Scoot y","
Bike",30000, 1000);
orderList[
1]=newOr der(
1235,"
Activa","Bi
ke",40000, 1000) ;
orderList[
2]=newOr der(
1236,"
Splendour "
, "
Bike",55000, 1000)
;
orderList[
3]=newOr der(
1237,"
Swift","Car"
,250000, 2000) ;
orderList[
4]=newOr der(
1238,"
Alt
o", "Car"
,200000, 7000) ;
doublet otal
Pr i
ce=Or der
Demo.cal
cul ateTotal
Pr i
ce(orderList
);
System. out.
printl
n(total
Pri
ce);

Or
der
[]or
der
Cat
egory=Order
Demo. f
indOr
derBy
Cat
egor
y(or
der
List
,"
Car
");
for(
Orderor
der:
order
Categor
y)
Syst
em.out.
pri
ntl
n(order.
getOr
der
Id(
)+order
.get
It
emName(
)
+or
der
.get
Cat
egor
y()+or
der
.get
Pri
ce(
)+order.
get
InsuranceAmount(
));
}

You might also like