Browse Source

Section 2 - Comparable

Nicholas Maidanos 8 years ago
parent
commit
551c6e0dcc

+ 4
- 0
src/main/java/com/zipcoder/payment/Check.java View File

62
     public void setId(long id) {
62
     public void setId(long id) {
63
         this.id = id;
63
         this.id = id;
64
     }
64
     }
65
+
65
     public String getAccountNumber(){
66
     public String getAccountNumber(){
66
         return this.accountNumber;
67
         return this.accountNumber;
67
     }
68
     }
68
 
69
 
70
+    public int compareTo(Payment o) {
71
+        return 0;
72
+    }
69
 }
73
 }

+ 12
- 0
src/main/java/com/zipcoder/payment/CreditCard.java View File

81
         return Integer.parseInt(lastFourString);
81
         return Integer.parseInt(lastFourString);
82
     }
82
     }
83
 
83
 
84
+    public int compareTo(Payment o) {
84
 
85
 
86
+        int result = this.getShortDescription().compareTo(o.getShortDescription());
87
+
88
+        if(result > 0){
89
+            return 1;
90
+        } else if(result < 0){
91
+            return -1;
92
+        } else {
93
+            return 0;
94
+        }
95
+
96
+    }
85
 }
97
 }

+ 1
- 2
src/main/java/com/zipcoder/payment/Payment.java View File

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
-public interface Payment {
3
+public interface Payment extends Comparable<Payment> {
4
 
4
 
5
     long getId();
5
     long getId();
6
 
6
 
8
 
8
 
9
     String getShortDescription();
9
     String getShortDescription();
10
 
10
 
11
-
12
 }
11
 }

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

47
         return sb.toString();
47
         return sb.toString();
48
     }
48
     }
49
 
49
 
50
-
50
+    public int compareTo(Payment o) {
51
+        return 0;
52
+    }
51
 }
53
 }

+ 4
- 0
src/test/java/com/zipcoder/payment/CheckTest.java View File

141
         String actual = ck.getShortDescription();
141
         String actual = ck.getShortDescription();
142
         assertEquals(expected, actual);
142
         assertEquals(expected, actual);
143
     }
143
     }
144
+
145
+    @Test
146
+    void compareTo() {
147
+    }
144
 }
148
 }

+ 15
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java View File

154
 
154
 
155
     }
155
     }
156
 
156
 
157
+    @Test
158
+    public void compareToTest() {
159
+        //Given
160
+        Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
161
+        Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
162
+
163
+        //Expect
164
+        int expected = -1;
165
+
166
+        //Actual
167
+        int actual = cc.compareTo(pp);
168
+
169
+        assertEquals(expected, actual);
170
+
171
+    }
157
 }
172
 }

+ 4
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java View File

104
 
104
 
105
         assertEquals(expect,actual);
105
         assertEquals(expect,actual);
106
     }
106
     }
107
+
108
+    @Test
109
+    void compareTo() {
110
+    }
107
 }
111
 }