CreditCard.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.zipcoder.payment;
  2. public class CreditCard implements Payment {
  3. private long id;
  4. private String payerName;
  5. private String number;
  6. private int expiredMonth;
  7. private int expiredYear;
  8. public CreditCard(long id, String payerName, String number, int expiredMonth, int expiredYear) {
  9. this.id = id;
  10. this.payerName = payerName;
  11. this.number = number;
  12. this.expiredMonth = expiredMonth;
  13. this.expiredYear = expiredYear;
  14. }
  15. public long getId() {
  16. return id;
  17. }
  18. public String getPayerName() {
  19. return payerName;
  20. }
  21. public String getNumber() {
  22. return number;
  23. }
  24. public int getExpiredMonth() {
  25. return expiredMonth;
  26. }
  27. public int getExpiredYear() {
  28. return expiredYear;
  29. }
  30. public String getShortDescription(){
  31. return String.format("CC %s %s %d/%d", payerName, number.substring(number.length() - 4, number.length()), expiredMonth, expiredYear);
  32. }
  33. public int compareTo(Payment p) {
  34. return this.getShortDescription().compareTo(p.getShortDescription());
  35. }
  36. }