shakila пре 8 година
родитељ
комит
cb50038f2e

+ 14
- 5
src/main/java/com/zipcoder/payment/Check.java Прегледај датотеку

7
     String accountNumber;
7
     String accountNumber;
8
     int compare;
8
     int compare;
9
 
9
 
10
-    public Check(){
11
-        id = 12345;
12
-        payerName = "Tia Mowry";
13
-        routingNumber = "987654321";
14
-        accountNumber = "0123456789";
10
+    public Check(long id, String payerName, String accountNumber, String routingNumber ){
11
+        this.id = 12345;
12
+        this.payerName = "Tia Mowry";
13
+        this.routingNumber = "987654321";
14
+        this.accountNumber = "0123456789";
15
         compare = 0;
15
         compare = 0;
16
     }
16
     }
17
 
17
 
18
+    public Check() {
19
+
20
+    }
21
+
22
+
23
+    public String getLastFour(String accountNumber){
24
+    return accountNumber.replace(accountNumber.substring(0, accountNumber.length()-4), "");
25
+    }
26
+
18
     public Long getId() {
27
     public Long getId() {
19
         return id;
28
         return id;
20
     }
29
     }

+ 6
- 0
src/main/java/com/zipcoder/payment/PayPal.java Прегледај датотеку

13
         compare = 0;
13
         compare = 0;
14
     }
14
     }
15
 
15
 
16
+    public PayPal(long id, String payerName, String email) {
17
+        this.id = id;
18
+        this.payerName = payerName;
19
+        this.email = email;
20
+    }
21
+
16
     public Long getId() {
22
     public Long getId() {
17
         return id;
23
         return id;
18
     }
24
     }

+ 28
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Прегледај датотеку

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
+import java.util.Arrays;
2
 
3
 
3
 public class PaymentPresenter {
4
 public class PaymentPresenter {
5
+    public String toString(Payment[] payments){
6
+        Arrays.sort(payments);
7
+        StringBuilder builder = new StringBuilder();
8
+        for(Payment o: payments){
9
+            o.getId();
10
+            o.getPayerName();
11
+            builder.append(o.getShortDescription()+ "\n");
12
+        }
13
+        return builder.toString();
14
+    }
4
 
15
 
16
+    public String toStringByPayerName(Payment[] payments){
17
+        Arrays.sort(payments, new PaymentSortByPayer());
18
+        StringBuilder builder = new StringBuilder();
19
+        for (Payment o: payments){
20
+            builder.append(o.getShortDescription()+ "\n");
21
+        }
22
+        return builder.toString();
23
+    }
24
+
25
+    public String toStringById(Payment[] payments){
26
+        Arrays.sort(payments, (Payment a, Payment b) -> Long.compare(a.getId(), b.getId()));
27
+        StringBuilder builder = new StringBuilder();
28
+        for (Payment o: payments){
29
+            builder.append(o.getShortDescription()+ "\n");
30
+        }
31
+        return builder.toString();
32
+    }
5
 }
33
 }

+ 11
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Прегледај датотеку

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

+ 17
- 17
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Прегледај датотеку

4
 import static org.junit.Assert.*;
4
 import static org.junit.Assert.*;
5
 
5
 
6
 
6
 
7
-public class PaymentPresenterTest1 {
7
+public class PaymentPresenterTest {
8
 
8
 
9
     @Test
9
     @Test
10
     public void toString1() {
10
     public void toString1() {
11
-        Payment[] payments = new payment.Payment[0];
11
+        Payment[] payments = new Payment[0];
12
         PaymentPresenter presenter = new PaymentPresenter();
12
         PaymentPresenter presenter = new PaymentPresenter();
13
         String expected = "";
13
         String expected = "";
14
 
14
 
19
 
19
 
20
     @Test
20
     @Test
21
     public void toString2(){
21
     public void toString2(){
22
-        Payment[] payments = new com.zipcoder.payment.Payment[2];
23
-        Payment payPal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com");
24
-        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
22
+        Payment[] payments = new Payment[2];
23
+        Payment PayPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
24
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
25
 
25
 
26
-        payment[0] = payPal;
27
-        payment[1] = check;
26
+        payments[0] = PayPal;
27
+        payments[1] = check;
28
 
28
 
29
         PaymentPresenter presenter = new PaymentPresenter();
29
         PaymentPresenter presenter = new PaymentPresenter();
30
         String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
30
         String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
35
 
35
 
36
     @Test
36
     @Test
37
     public void toStringByPayerName() {
37
     public void toStringByPayerName() {
38
-        Payment[] payments = new com.zipcoder.payment.Payment[2];
39
-        Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com");
40
-        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
38
+        Payment[] payments = new Payment[2];
39
+        Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
40
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
41
 
41
 
42
-        payment[0] = paypal;
43
-        payment[1] = check;
42
+        payments[0] = paypal;
43
+        payments[1] = check;
44
 
44
 
45
         PaymentPresenter presenter = new PaymentPresenter();
45
         PaymentPresenter presenter = new PaymentPresenter();
46
         String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
46
         String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
51
 
51
 
52
     @Test
52
     @Test
53
     public void toStringById(){
53
     public void toStringById(){
54
-        Payment[] payments = new com.zipcoder.payment.Payment[2];
55
-        Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com");
56
-        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
54
+        Payment[] payments = new Payment[2];
55
+        Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
56
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
57
 
57
 
58
-        payment[0] = paypal;
59
-        payment[1] = check;
58
+        payments[0] = paypal;
59
+        payments[1] = check;
60
 
60
 
61
         PaymentPresenter presenter = new PaymentPresenter();
61
         PaymentPresenter presenter = new PaymentPresenter();
62
         String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
62
         String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";