M
Marilyn Hart
Hi
I hope there is someone out there that may be able to help me.
I have a Hashmap called that contains Bank Account objects,
it is made up as follows.
Bank Acc Number - int
Bank Acc Type - String
Cust Number - int
Cust Name -String
Balance - double
I am trying to create an Iterator that will search each object in turn and
pass the Acc Type and Balance into a calculate Interest Method in another
class which will return the interest due. Then output on a simple output
dialog.
This is the code I have but it keeps giving me a Null Pointer Exception
error.
Where am I going wrong?
Iterator i = accList.keySet().iterator();
while (i.hasNext())
{
TypesOfAccount tempAcc = ((TypesOfAccount)accList.get(i));
accType = tempAcc.getType(); //String
balance = tempAcc.getBalance(); //double
interest = tempAcc.calcInterest(accType, balance);
total += interest; //double
}
JOptionPane.showMessageDialog(null,
"Interest on all accounts is " + total,
"Interest on All Accounts.",
JOptionPane.OK_OPTION);
What are the differences between keySet, valueSet and entrySet?
Which should I be using?
TIA
Paul
I hope there is someone out there that may be able to help me.
I have a Hashmap called that contains Bank Account objects,
it is made up as follows.
Bank Acc Number - int
Bank Acc Type - String
Cust Number - int
Cust Name -String
Balance - double
I am trying to create an Iterator that will search each object in turn and
pass the Acc Type and Balance into a calculate Interest Method in another
class which will return the interest due. Then output on a simple output
dialog.
This is the code I have but it keeps giving me a Null Pointer Exception
error.
Where am I going wrong?
Iterator i = accList.keySet().iterator();
while (i.hasNext())
{
TypesOfAccount tempAcc = ((TypesOfAccount)accList.get(i));
accType = tempAcc.getType(); //String
balance = tempAcc.getBalance(); //double
interest = tempAcc.calcInterest(accType, balance);
total += interest; //double
}
JOptionPane.showMessageDialog(null,
"Interest on all accounts is " + total,
"Interest on All Accounts.",
JOptionPane.OK_OPTION);
What are the differences between keySet, valueSet and entrySet?
Which should I be using?
TIA
Paul