|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-# Polymorphism Payment Lab
|
|
|
1
|
+# Polymorphism com.zipcoder.payment.Payment Lab
|
|
2
|
2
|
|
|
3
|
3
|
## Objectives
|
|
4
|
4
|
|
|
|
@@ -7,15 +7,15 @@
|
|
7
|
7
|
- To learn [lambda function](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html)
|
|
8
|
8
|
|
|
9
|
9
|
# Section 1 - Setting up the classes
|
|
10
|
|
-## Part 1 - Payment
|
|
11
|
|
-1. Create a `Payment` interface
|
|
|
10
|
+## Part 1 - com.zipcoder.payment.Payment
|
|
|
11
|
+1. Create a `com.zipcoder.payment.Payment` interface
|
|
12
|
12
|
- The class should define a `getId()` method which returns a Long
|
|
13
|
13
|
- The class should define a `getPayerName()` method which returns a String
|
|
14
|
14
|
- The class should define a `getShortDescription` method which returns a String
|
|
15
|
15
|
|
|
16
|
16
|
## Part 2 - Credit Card
|
|
17
|
17
|
1. Create a `CreditCardTest` test class
|
|
18
|
|
-2. Create a `CreditCard` class which implements the `Payment` interface
|
|
|
18
|
+2. Create a `CreditCard` class which implements the `com.zipcoder.payment.Payment` interface
|
|
19
|
19
|
3. Add the required methods from the interface
|
|
20
|
20
|
4. Add getter and setter test for an id
|
|
21
|
21
|
- Add a Long id field
|
|
|
@@ -31,7 +31,7 @@
|
|
31
|
31
|
|
|
32
|
32
|
## Part 3 - Check
|
|
33
|
33
|
1. Create a `CheckTest` test class
|
|
34
|
|
-2. Create a `Check` class which implements the `Payment` interface
|
|
|
34
|
+2. Create a `Check` class which implements the `com.zipcoder.payment.Payment` interface
|
|
35
|
35
|
3. Add the required methods from the interface
|
|
36
|
36
|
4. Add getter and setter test for an id
|
|
37
|
37
|
- Add a Long id field
|
|
|
@@ -46,7 +46,7 @@
|
|
46
|
46
|
|
|
47
|
47
|
## Part 4 - Paypal
|
|
48
|
48
|
1. Create a `PayPalTest` test class
|
|
49
|
|
-2. Create a `PayPal` class which implements the `Payment` interface
|
|
|
49
|
+2. Create a `PayPal` class which implements the `com.zipcoder.payment.Payment` interface
|
|
50
|
50
|
3. Add the required methods from the interface
|
|
51
|
51
|
4. Add getter and setter test for an id
|
|
52
|
52
|
- Add a Long id field
|
|
|
@@ -60,19 +60,19 @@
|
|
60
|
60
|
|
|
61
|
61
|
# Section 2 - Comparable
|
|
62
|
62
|
Note: You may use the String/Long compareTo methods in your code
|
|
63
|
|
-1. Edit the `Payment` class to extends the Comparable interface
|
|
64
|
|
- - `public interface Payment extends Comparable<Payment>`
|
|
|
63
|
+1. Edit the `com.zipcoder.payment.Payment` class to extends the Comparable interface
|
|
|
64
|
+ - `public interface com.zipcoder.payment.Payment extends Comparable<com.zipcoder.payment.Payment>`
|
|
65
|
65
|
- This indicate that payment can be comparable, which means it can be sorted
|
|
66
|
66
|
2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
|
|
67
|
67
|
3. Create a test for the `compareTo` method. Compare using the getShortDescription()
|
|
68
|
|
- - Example: Given Payment of type Paypal with the short description of `Paypal Tia Mowry tia@mowry.com` and a Check with the short description of `Check Tia Mowry ***4551`, then the `compareTo` method should return a number larger than 0
|
|
|
68
|
+ - Example: Given com.zipcoder.payment.Payment of type Paypal with the short description of `Paypal Tia Mowry tia@mowry.com` and a Check with the short description of `Check Tia Mowry ***4551`, then the `compareTo` method should return a number larger than 0
|
|
69
|
69
|
- The `compareTo` method will return number larger than 0 if this payment comes after payment2
|
|
70
|
70
|
- The `compareTo` method will return number 0 if this payment has the same information
|
|
71
|
71
|
- The `compareTo` method will return number less than 0 if this payment comes before payment2
|
|
72
|
72
|
4. Add the code necessary to make the test pass
|
|
73
|
73
|
5. Create a new `PaymentSortByPayer` class which implements `java.util.Comparator`
|
|
74
|
74
|
- This class will sort by payer name
|
|
75
|
|
- - `public class PaymentSortByPayer implements Comparator<Payment>`
|
|
|
75
|
+ - `public class PaymentSortByPayer implements Comparator<com.zipcoder.payment.Payment>`
|
|
76
|
76
|
6. Add the required `compare` method from the Comparator
|
|
77
|
77
|
7. Create a test to compare two payment
|
|
78
|
78
|
- The `compare` method will return number larger than 0 if payment1 comes after payment2
|
|
|
@@ -85,7 +85,7 @@ Note: You may use the String/Long compareTo methods in your code
|
|
85
|
85
|
- When there is no payment
|
|
86
|
86
|
|
|
87
|
87
|
```
|
|
88
|
|
- Payment[] payments = new Payment[0];
|
|
|
88
|
+ com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[0];
|
|
89
|
89
|
PaymentPresenter presenter = new PaymentPresenter();
|
|
90
|
90
|
String expected = "";
|
|
91
|
91
|
|
|
|
@@ -97,9 +97,9 @@ Note: You may use the String/Long compareTo methods in your code
|
|
97
|
97
|
- When there are multiple payments, you need to sort it first, then build the string using the short description
|
|
98
|
98
|
|
|
99
|
99
|
```
|
|
100
|
|
- Payment[] payments = new Payment[2];
|
|
101
|
|
- Payment paypal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com");
|
|
102
|
|
- Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
|
100
|
+ com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
|
|
|
101
|
+ com.zipcoder.payment.Payment paypal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com");
|
|
|
102
|
+ com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
103
|
103
|
|
|
104
|
104
|
payment[0] = paypal;
|
|
105
|
105
|
payment[1] = check;
|
|
|
@@ -115,9 +115,9 @@ Note: You may use the String/Long compareTo methods in your code
|
|
115
|
115
|
- When there are multiple payments, you need to sort by calling the `PaymentSortByPayer` class to sort, then build the string using the short description
|
|
116
|
116
|
|
|
117
|
117
|
```
|
|
118
|
|
- Payment[] payments = new Payment[2];
|
|
119
|
|
- Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com");
|
|
120
|
|
- Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
|
118
|
+ com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
|
|
|
119
|
+ com.zipcoder.payment.Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com");
|
|
|
120
|
+ com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
121
|
121
|
|
|
122
|
122
|
payment[0] = paypal;
|
|
123
|
123
|
payment[1] = check;
|
|
|
@@ -133,9 +133,9 @@ Note: You may use the String/Long compareTo methods in your code
|
|
133
|
133
|
- When there are multiple payments, you need to sort by creating a lambda to sort the payment by id, then build the string using the short description
|
|
134
|
134
|
|
|
135
|
135
|
```
|
|
136
|
|
- Payment[] payments = new Payment[2];
|
|
137
|
|
- Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com");
|
|
138
|
|
- Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
|
136
|
+ com.zipcoder.payment.Payment[] payments = new com.zipcoder.payment.Payment[2];
|
|
|
137
|
+ com.zipcoder.payment.Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com");
|
|
|
138
|
+ com.zipcoder.payment.Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
|
|
139
|
139
|
|
|
140
|
140
|
payment[0] = paypal;
|
|
141
|
141
|
payment[1] = check;
|