shakila 8 лет назад
Родитель
Сommit
ba36a64876

+ 14
- 1
src/main/java/com/zipcoder/payment/Check.java Просмотреть файл

@@ -5,12 +5,14 @@ public class Check implements Payment {
5 5
     String payerName;
6 6
     String routingNumber;
7 7
     String accountNumber;
8
+    int compare;
8 9
 
9 10
     public Check(){
10 11
         id = 12345;
11 12
         payerName = "Tia Mowry";
12 13
         routingNumber = "987654321";
13 14
         accountNumber = "0123456789";
15
+        compare = 0;
14 16
     }
15 17
 
16 18
     public Long getId() {
@@ -46,6 +48,17 @@ public class Check implements Payment {
46 48
     }
47 49
 
48 50
     public int compareTo(Payment o) {
49
-        return 0;
51
+        if (this.getShortDescription().compareTo(o.getShortDescription()) < 0){
52
+            compare = -1;
53
+        }
54
+        else if (this.getShortDescription().compareTo(o.getShortDescription()) > 0){
55
+            compare = 1;
56
+        }
57
+
58
+        else{
59
+            compare = 0;
60
+        }
61
+
62
+        return compare;
50 63
     }
51 64
 }

+ 14
- 1
src/main/java/com/zipcoder/payment/PayPal.java Просмотреть файл

@@ -4,11 +4,13 @@ public class PayPal implements Payment {
4 4
         long id;
5 5
         String payerName;
6 6
         String email;
7
+        int compare;
7 8
 
8 9
     public PayPal(){
9 10
         id = 12345;
10 11
         payerName = "Tia Mowry";
11 12
         email = "tia@mowry.com";
13
+        compare = 0;
12 14
     }
13 15
 
14 16
     public Long getId() {
@@ -37,6 +39,17 @@ public class PayPal implements Payment {
37 39
     }
38 40
 
39 41
     public int compareTo(Payment o) {
40
-        return 0;
42
+        if (this.getShortDescription().compareTo(o.getShortDescription()) < 0){
43
+            compare = -1;
44
+        }
45
+        else if (this.getShortDescription().compareTo(o.getShortDescription()) > 0){
46
+            compare = 1;
47
+        }
48
+
49
+        else{
50
+            compare = 0;
51
+        }
52
+
53
+        return compare;
41 54
     }
42 55
 }

+ 26
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Просмотреть файл

@@ -44,4 +44,30 @@ public class PayPalTest {
44 44
          String actualGetShortDescription = payPal.getShortDescription();
45 45
         assertEquals(expectedGetShortDescription, actualGetShortDescription);
46 46
     }
47
+
48
+    @Test
49
+    public void compareTo1() {
50
+        CreditCard creditCard = new CreditCard();
51
+        PayPal payPal = new PayPal();
52
+        int expectedCompareTo = 1;
53
+        int actualCompareTo = payPal.compareTo(creditCard);
54
+        assertEquals(expectedCompareTo, actualCompareTo);
55
+    }
56
+
57
+    @Test
58
+    public void compareTo2() {
59
+        Check check = new Check();
60
+        PayPal payPal = new PayPal();
61
+        int expectedCompareTo = 1;
62
+        int actualCompareTo = payPal.compareTo(check);
63
+        assertEquals(expectedCompareTo, actualCompareTo);
64
+    }
65
+
66
+    @Test
67
+    public void compareTo3() {
68
+        PayPal payPal = new PayPal();
69
+        int expectedCompareTo = 0;
70
+        int actualCompareTo = payPal.compareTo(payPal);
71
+        assertEquals(expectedCompareTo, actualCompareTo);
72
+    }
47 73
 }