Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. public class User {
  2. private String userId;
  3.  
  4. public User(Long id){
  5. // Constructor
  6. this.userId = id.toString();
  7. }
  8.  
  9. public String getNumber(){
  10. return userId; // return the account number
  11. }
  12.  
  13. public ArrayList getBookings() throws Exception{
  14. try{
  15. List dbBookingList = Db.getBookings(userId.trim()); //Get the list of bookings
  16. ArrayList bookingList = new ArrayList();
  17. int i;
  18. for(i=0; i<dbBookingList.size(); i++){
  19. DbRow dbRow = (DbRow) dbBookingList.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 product = row.getValueForField(β€œprod”);
  34. return new Transaction(product, currencyAmountInPounds); // return the new Transaction object
  35. }
  36.  
  37. // Override the equals method
  38. public boolean equals(User o) {
  39. return o.getNumber() == getNumber(); // check account numbers are the same
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement