Last active
October 26, 2018 11:21
-
-
Save CristianoPassos/695f88427cf009fe1e08daf733d09a26 to your computer and use it in GitHub Desktop.
Here’s a class one of your interns wrote. You’re reviewing it before it goes to QA.
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 { | |
List dbTransactionList = Db.getTransactions(accountNumber.trim()); | |
//Get the list of transactions | |
ArrayList transactionList = new ArrayList(); | |
int i; | |
for (i = 0; i < dbTransactionList.size(); i++) { | |
DbRow dbRow = (DbRow) dbTransactionList.get(0); | |
Transaction trans = makeTransactionFromDbRow(dbRow); | |
transactionList.add(trans); | |
} | |
return transactionList; | |
} catch (SQLException ex) { | |
// There was a database error | |
throw new Exception("Can't retrieve transactions from database"); | |
} | |
} | |
public Transaction makeTransactionFromDbRow(DbRow row) { | |
double amountInPounds = Double.parseDouble(row.getValueForField("amt")); | |
String description = row.getValueForField("desc"); | |
return new Transaction(description, amountInPounds); | |
// 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