Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public class Account {
  2. private String accountNumber;
  3.  
  4. public Account(String accountNumber){
  5. // Constructor
  6. this.accountNumber = accountNumber;
  7. }
  8.  
  9. public String getAccountNumber(){
  10. return accountNumber; // return the account number
  11. }
  12.  
  13. public ArrayList getTransactions() throws Exception{
  14. try{
  15. List dbTransactionList = Db.getTransactions(accountNumber.trim()); //Get the list of transactions
  16. ArrayList transactionList = new ArrayList();
  17. int i;
  18. for(i=0; i<dbTransactionList.size(); i++){
  19. DbRow dbRow = (DbRow) dbTransactionList.get(i);
  20. Transaction trans = makeTransactionFromDbRow(dbRow);
  21. transactionList.add(trans);
  22. }
  23. return transactionList;
  24.  
  25. } catch (SQLException ex){
  26. // There was a database error
  27. throw new Exception("Can't retrieve transactions from the database");
  28. }
  29. }
  30.  
  31. public Transaction makeTransactionFromDbRow(DbRow row){
  32. double currencyAmountInPounds = Double.parseDouble(row.getValueForField("amt"));
  33. String description = row.getValueForField("desc");
  34. return new Transaction(description, currencyAmountInPounds); // return the new Transaction object
  35. }
  36.  
  37. // Override the equals method
  38. public boolean equals(Account o) {
  39. return o.getAccountNumber() == getAccountNumber(); // check account numbers are the same
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement