CreditCard.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.zipcoder.payment;
  2. public class CreditCard implements Payment {
  3. private long id;
  4. private int month;
  5. private int year;
  6. private String number;
  7. private String name;
  8. public CreditCard(long id, int month, int year, String number, String name){
  9. this.id = id;
  10. this.month = month;
  11. this.year = year;
  12. this.number = number;
  13. this.name = name;
  14. }
  15. public CreditCard(long id){
  16. this.id = id;
  17. }
  18. public CreditCard(long id,String name,String number){
  19. this.id=id;
  20. this.name = name;
  21. this.number = number;
  22. }
  23. public CreditCard(String name){
  24. this.name = name;
  25. }
  26. public CreditCard(){
  27. }
  28. public long getId() {
  29. return id;
  30. }
  31. public void setId(long id){
  32. this.id = id;
  33. }
  34. public void setPayerName(String name){
  35. this.name = name;
  36. }
  37. public String getPayerName() {
  38. return name;
  39. }
  40. public void setExpiredMonth(int month){
  41. this.month = month;
  42. }
  43. public int getExpiredMonth(){
  44. return month;
  45. }
  46. public void setExpiredYear(int year){
  47. this.year = year;
  48. }
  49. public int getExpiredYear(){
  50. return year;
  51. }
  52. public String getNumber(){
  53. return number;
  54. }
  55. public void setNumber(String number){
  56. this.number = number;
  57. }
  58. public String getShortDescription() {
  59. return "CC " + getPayerName() +" "+ getNumber() +" "+ getExpiredMonth()+"/"+getExpiredYear();
  60. }
  61. public int compareTo(Payment o) {
  62. if(this.getShortDescription().compareTo(o.getShortDescription())== 0){
  63. return 0;
  64. }
  65. else if(this.getShortDescription().compareTo(o.getShortDescription()) < 0){
  66. return -1;
  67. }
  68. else if(this.getShortDescription().compareTo(o.getShortDescription())>0){
  69. return 1;
  70. }
  71. else{
  72. return 101010;
  73. }
  74. }
  75. }