Check.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.zipcoder.payment;
  2. public class Check implements Payment {
  3. /*
  4. Create a `Check` class which implements the `Payment` interface
  5. 3. Add the required methods from the interface
  6. 4. Add getter and setter test for an id
  7. - Add a Long id field
  8. - Add a getter and setter method to make the test pass
  9. 5. Repeat step 4 for the following fields:
  10. - String payerName
  11. - String routing number
  12. - String accountNumber
  13. 6. Implement the `getShortDescription` to return `Check [payerName] ***[last 4 digit of the account]`
  14. - ex: `Check Tia Mowry ***4551`
  15. 7. You may create any type of constructor or methods that will with this lab
  16. */
  17. long id;
  18. String payerName;
  19. String routingNumber;
  20. String accountNumber;
  21. public Check() {
  22. }
  23. public Check(long id, String payerName, String routingNumber, String accountNumber) {
  24. this.id = id;
  25. this.payerName = payerName;
  26. this.routingNumber = routingNumber;
  27. this.accountNumber = accountNumber;
  28. }
  29. public long getId() {
  30. return id;
  31. }
  32. public void setId(long id) {
  33. this.id = id;
  34. }
  35. public String getpayerName() {
  36. return payerName;
  37. }
  38. public void setPayerName(String payerName) {
  39. this.payerName = payerName;
  40. }
  41. public String getRoutingNumber() {
  42. return routingNumber;
  43. }
  44. public void setRoutingNumber(String routingNumber) {
  45. this.routingNumber = routingNumber;
  46. }
  47. public String getAccountNumber() {
  48. return accountNumber;
  49. }
  50. public void setAccountNumber(String accountNumber) {
  51. this.accountNumber = accountNumber;
  52. }
  53. public String getLastfourAccountNumber() {
  54. String str = "";
  55. String acctNo = this.accountNumber.toString();
  56. if (acctNo.length() > 4) {
  57. str = acctNo.substring(acctNo.length() - 4);
  58. } else {
  59. str = acctNo;
  60. }
  61. return str;
  62. }
  63. @Override
  64. public String getShortDescription() {
  65. return "Check " + this.payerName + " ***" + this.getLastfourAccountNumber() ;
  66. }
  67. @Override
  68. public int compareTo(Payment other) {
  69. return this.getShortDescription() .compareTo(other.getShortDescription() );
  70. }
  71. }