CreditCard.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.zipcoder.payment;
  2. public class CreditCard implements Payment {
  3. Long id;
  4. String payerName;
  5. String number;
  6. int expiredMonth;
  7. int expiredYear;
  8. public CreditCard(){
  9. }
  10. public CreditCard(String name, String number, int expiredMonth, int expiredYear){
  11. this.payerName = name;
  12. this.number = number;
  13. this.expiredMonth = expiredMonth;
  14. this.expiredYear = expiredYear;
  15. }
  16. public int getExpiredYear() {
  17. return expiredYear;
  18. }
  19. public void setExpiredYear(int expiredYear) {
  20. this.expiredYear = expiredYear;
  21. }
  22. public int getExpiredMonth() {
  23. return expiredMonth;
  24. }
  25. public void setExpiredMonth(int expiredMonth) {
  26. this.expiredMonth = expiredMonth;
  27. }
  28. public String getNumber() {
  29. return number;
  30. }
  31. public void setNumber(String number) {
  32. this.number = number;
  33. }
  34. public Long getId(){
  35. return id;
  36. }
  37. public void setId(Long id){
  38. this.id = id;
  39. }
  40. public String getPayerName(){
  41. return payerName;
  42. }
  43. public void setPayerName(String payerName) {
  44. this.payerName = payerName;
  45. }
  46. public String getShortDescription(){
  47. String result = "CC " + getPayerName() + " " + lastFour(getNumber()) + " " + getExpiredMonth() + "/" + getExpiredYear();
  48. return result;
  49. }
  50. public String lastFour(String number){
  51. return number.substring(number.length()-4);
  52. }
  53. public int compareTo(Payment o) {
  54. return this.getShortDescription().compareTo(o.getShortDescription());
  55. }
  56. }