|
|
|
|
61
|
# Section 2 - Comparable
|
61
|
# Section 2 - Comparable
|
62
|
Note: You may use the String/Long compareTo methods in your code
|
62
|
Note: You may use the String/Long compareTo methods in your code
|
63
|
1. Edit the `Payment` class to extends the Comparable interface
|
63
|
1. Edit the `Payment` class to extends the Comparable interface
|
64
|
- - `public class Payment extends Comparable<Payment>`
|
|
|
|
|
64
|
+ - `public interface Payment extends Comparable<Payment>`
|
65
|
- This indicate that payment can be comparable, which means it can be sorted
|
65
|
- This indicate that payment can be comparable, which means it can be sorted
|
66
|
2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
|
66
|
2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
|
67
|
3. Create a test for the `compareTo` method. Compare using the getShortDescription()
|
67
|
3. Create a test for the `compareTo` method. Compare using the getShortDescription()
|
|
|
|
|
123
|
PaymentPresenter presenter = new PaymentPresenter();
|
123
|
PaymentPresenter presenter = new PaymentPresenter();
|
124
|
String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
|
124
|
String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
|
125
|
|
125
|
|
126
|
- String actual = presenter.toString(payments);
|
|
|
|
|
126
|
+ String actual = presenter.toStringByPayerName(payments);
|
127
|
assertEquals(expected, actual);
|
127
|
assertEquals(expected, actual);
|
128
|
```
|
128
|
```
|
129
|
|
129
|
|
|
|
|
|
140
|
PaymentPresenter presenter = new PaymentPresenter();
|
140
|
PaymentPresenter presenter = new PaymentPresenter();
|
141
|
String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
|
141
|
String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
|
142
|
|
142
|
|
143
|
- String actual = presenter.toString(payments);
|
|
|
|
|
143
|
+ String actual = presenter.toStringById(payments);
|
144
|
assertEquals(expected, actual);
|
144
|
assertEquals(expected, actual);
|
145
|
```
|
145
|
```
|