Last active
June 28, 2016 22:17
-
-
Save EronWright/0e6992fb126af4359a24784a5aa86893 to your computer and use it in GitHub Desktop.
Account.java - Sample code for instructional purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Account { | |
private String accountNumber; | |
public Account(String accountNumber) { | |
// Constructor | |
this.accountNumber = accountNumber; | |
} | |
public String getAccountNumber() { | |
return accountNumber; // return the account number | |
} | |
public ArrayList getTransactions() throws Exception { | |
try { | |
// Get the list of transactions | |
List dbTransactionList = Db.getTransactions(accountNumber.trim()); | |
ArrayList transactionList = new ArrayList(); | |
int i; | |
for(i = 0; i < dbTransactionList.size(); i++) { | |
DbRow row = (DbRow) dbTransactionList.get(i); | |
Transaction trans = makeTransactionFromDbRow(row); | |
transactionList.add(trans); | |
} | |
return transactionList; | |
} catch (SQLException ex) { | |
// There was a database error | |
throw new Exception("Can't retrieve transactions from the database"); | |
} | |
} | |
public Transaction makeTransactionFromDbRow(DbRow row) { | |
double currencyAmountInPounds = Double.parseDouble(row.getValueForField("amt")); | |
String description = row.getValueForField("desc"); | |
return new Transaction(description, currencyAmountInPounds); // return the new Transaction object | |
} | |
// Override the equals method | |
public boolean equals(Account o) { | |
return o.getAccountNumber() == getAccountNumber(); // check account numbers are the same | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment