rjsmall90 8 years ago
parent
commit
8e9bebf53c

+ 5
- 3
src/main/java/com/zipcoder/payment/Check.java View File

6
     String routingNumber;
6
     String routingNumber;
7
     String accountNumber;
7
     String accountNumber;
8
 
8
 
9
-    public Check () {}
10
 
9
 
11
-    public Check(Long id, String payerName, String accountNumber, String routingNumber){
10
+    public Check () {}
12
 
11
 
12
+    public Check(Long id, String payerName, String routingNumber, String accountNumber){
13
+        this.id = id; this.payerName = payerName;
14
+        this.accountNumber = lastFourAccount(accountNumber); this.routingNumber = routingNumber;
13
     }
15
     }
14
 
16
 
15
     @Override
17
     @Override
35
 
37
 
36
     }
38
     }
37
 
39
 
38
-
39
     @Override
40
     @Override
40
     public String getShortDescription() {
41
     public String getShortDescription() {
41
         return "Check " + getPayerName() + " ***" + getAccountNumber();
42
         return "Check " + getPayerName() + " ***" + getAccountNumber();
55
 
56
 
56
     public void setAccountNumber(String accountNumber) {
57
     public void setAccountNumber(String accountNumber) {
57
         this.accountNumber = accountNumber;
58
         this.accountNumber = accountNumber;
59
+
58
     }
60
     }
59
 
61
 
60
 
62
 

+ 10
- 0
src/main/java/com/zipcoder/payment/CheckTest.java View File

103
 
103
 
104
         assertEquals(expected, actual);
104
         assertEquals(expected, actual);
105
     }
105
     }
106
+
107
+    @Test
108
+    public void lastFourAccount() {
109
+        String x = "1234567";
110
+
111
+        String expected = "4567";
112
+        String actual = check.lastFourAccount(x);
113
+
114
+        assertEquals(expected, actual);
115
+    }
106
 }
116
 }

+ 22
- 6
src/main/java/com/zipcoder/payment/PaymentPresenter.java View File

6
 
6
 
7
 
7
 
8
     public String toString(Payment[] payment) {
8
     public String toString(Payment[] payment) {
9
+        Arrays.sort(payment);
9
 
10
 
10
-        if (payment.length > 1)
11
-            return payment[0].getShortDescription() + "\n" + payment[1].getShortDescription() + "\n";
12
-        else return Arrays.toString(payment).replace("[]", "");
11
+        StringBuilder build = new StringBuilder();
12
+        for(Payment o : payment) build.append(o.getShortDescription()+"\n");
13
+        return build.toString();
13
 
14
 
14
-        for (Payment o : payment){
15
-             o.getId(); o.getPayerName();
15
+//             o.getId(); o.getPayerName();
16
         }
16
         }
17
+
18
+    public String toStringByPayerName(Payment[] payment) {
19
+        Arrays.sort(payment, new PaymentSortByPayer());
20
+
21
+        StringBuilder build = new StringBuilder();
22
+        for(Payment o : payment) build.append(o.getShortDescription()+"\n");
23
+        return build.toString();
24
+    }
25
+
26
+    public String toStringById(Payment[] payment) {
27
+        Arrays.sort(payment, new PaymentSortByPayer());
28
+
29
+        StringBuilder build = new StringBuilder();
30
+        for(Payment o : payment) build.append(o.getShortDescription()+"\n");
31
+        return build.toString();
17
     }
32
     }
33
+}
34
+
18
 
35
 
19
 
36
 
20
 
37
 
22
 
39
 
23
 
40
 
24
 
41
 
25
-}

+ 33
- 5
src/main/java/com/zipcoder/payment/PaymentPresenterTest.java View File

21
     @Test
21
     @Test
22
     public void toStringMultiplePayments() {
22
     public void toStringMultiplePayments() {
23
         Payment[] payment = new Payment[2];
23
         Payment[] payment = new Payment[2];
24
-        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
25
-        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
24
+        Payment paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
25
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
26
 
26
 
27
 
27
 
28
         payment[0] = paypal;
28
         payment[0] = paypal;
35
         assertEquals(expected, actual);
35
         assertEquals(expected, actual);
36
     }
36
     }
37
 
37
 
38
-//        paypal.setId(4L); paypal.setPayerName("Tia Mowry"); paypal.setEmail("tia@mowry.com");
39
-//        check.setId(81L); check.setPayerName("Tia Mowry"); check.setAccountNumber("11432543");
40
-//        check.setRoutingNumber("134344551");
38
+    @Test
39
+    public void toStringByPayerName() {
40
+        Payment[] payment = new Payment[2];
41
+        Payment paypal = new Paypal(4L, "Tamara Mowry", "tamara@mowry.com");
42
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
43
+
44
+        payment[0] = paypal;
45
+        payment[1] = check;
46
+
47
+        PaymentPresenter presenter = new PaymentPresenter();
48
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
49
+
50
+        String actual = presenter.toStringByPayerName(payment);
51
+        assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void toStringById() {
56
+        Payment[] payment = new Payment[2];
57
+        Payment paypal = new Paypal(120L, "Tamara Mowry", "tamara@mowry.com");
58
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
59
+
60
+        payment[0] = paypal;
61
+        payment[1] = check;
62
+
63
+        PaymentPresenter presenter = new PaymentPresenter();
64
+        String expected = "Paypal Tia Mowry tamara@mowry.com\nCheck Tamara Mowry ***4551\n";
65
+
66
+        String actual = presenter.toStringById(payment);
67
+        assertEquals(expected, actual);
41
 
68
 
42
     }
69
     }
70
+}
43
 
71
 
44
 
72
 

+ 14
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java View File

1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+
7
+    public PaymentSortByPayer(){
8
+
9
+    }
10
+
11
+    public int compare(Payment o1, Payment o2) {
12
+        return o1.getPayerName().compareTo(o2.getPayerName());
13
+    }
14
+}

+ 1
- 0
src/main/java/com/zipcoder/payment/Paypal.java View File

8
     public Paypal () {}
8
     public Paypal () {}
9
 
9
 
10
     public Paypal(Long id, String payerName, String email){
10
     public Paypal(Long id, String payerName, String email){
11
+        this.id = id; this.payerName = payerName; this.email = email;
11
 
12
 
12
     }
13
     }
13
 
14