how to throw message in this senario

in the arraylist i have chargeid's and their corresponding billamount;

045--0
162--999
225--900

for above case some charges has billamount then  i dont want to throw message;

 if any chargeid's doesn't have billamount at that time only i want to throw message at client side;
LVL 20
chaitu chaituAsked:
Who is Participating?
 
koppchaCommented:
This should do what you want just keep a flag check

public boolean check() throws OwnException{
Iterator HousedocumentchargesIterator = yourArrayList.Iterator();
int  passed = 1;
while(HousedocumentchargesIterator.hasNext()){
Housedocumentcharges  housedocumentcharges= (Housedocumentcharges )usedocumentchargesIterator.next()
if(housedocumentcharges.getBillamount !=0){
passed = 0;
break;
}
}
if (passed==0){
throw new OwnException;
}

return true
}
0
 
TimYatesCommented:
>>  i dont want to throw message;

What do you mean "throw message"?

You talking about exceptions?
0
 
chaitu chaituAuthor Commented:
yesss
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
koppchaCommented:
It would better to use HashMap with chargeId's as key and billamount as values so that in your case you can just check if that particular chargeId key exist..if it doesn't then throw the message if it exists get the values of the key if the value is zero then also throw the message.
 
0
 
chaitu chaituAuthor Commented:
i didnt get u;my charge's stored  in arraylist of Housedocumentcharges object
0
 
koppchaCommented:
Ok then iterate throw each element and take each object oy type Housedocumentcharges .In the object you might be having some getter methods to get the charge and billamount if billamount is zero for that particular object then throw the message

public boolean check() throws OwnException{
Iterator HousedocumentchargesIterator = yourArrayList.Iterator();
while(HousedocumentchargesIterator.hasNext()){
Housedocumentcharges  housedocumentcharges= (Housedocumentcharges )usedocumentchargesIterator.next()
if(housedocumentcharges.getBillamount==0){
throw new OwnException;
}
}
return true
}
0
 
chaitu chaituAuthor Commented:
if i have 10 chargeid's and one chargeid will have bill amount at that i dont want to throw a message;

if all the 10 chargeid's have no billamount's at that time only i want throw the exception
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.