|
|
8 лет назад | |
|---|---|---|
| src | 8 лет назад | |
| .gitignore | 8 лет назад | |
| README.MD | 8 лет назад | |
| pom.xml | 8 лет назад |
Comparable interfacePayment interface
getId() method which returns a LonggetPayerName() method which returns a StringgetShortDescription method which returns a StringCreditCardTest test classCreditCard class which implements the Payment interfacegetShortDescription to return CC [payerName] [last 4 digit of the number] [expiredMonth]/[expiredYear]
CC Tia Mowry 4551 10/2019CheckTest test classCheck class which implements the Payment interfacegetShortDescription to return Check [payerName] ***[last 4 digit of the account]
Check Tia Mowry ***4551PayPalTest test classPayPal class which implements the Payment interfacegetShortDescription to return Paypal [payerName] [email]
Paypal Tia Mowry tia@mowry.comNote: You may use the String/Long compareTo methods in your code
Payment class to extends the Comparable interface
public class Payment extends Comparable<Payment>compareTo method. Compare using the getShortDescription()
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 0compareTo method will return number larger than 0 if this payment comes after payment2compareTo method will return number 0 if this payment has the same informationcompareTo method will return number less than 0 if this payment comes before payment2PaymentSortByPayer class which implements java.util.Comparator
public class PaymentSortByPayer implements Comparator<Payment>compare method from the Comparatorcompare method will return number larger than 0 if payment1 comes after payment2compare method will return number 0 if the payment has the same informationcompare method will return number less than 0 if payment1 comes before payment2PaymentPresenterTestCreate a test case to test the toString method of the PaymentPresenter class
String actual = presenter.toString(payments);
assertEquals(expected, actual);
- When there are multiple payments, you need to sort it first, then build the string using the short description
Payment[] payments = new Payment[2]; Payment paypal = new PayPayl(4L, "Tia Mowry", "tia@mowry.com"); Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
payment[0] = paypal;
PaymentPresenter presenter = new PaymentPresenter(); String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
String actual = presenter.toString(payments); assertEquals(expected, actual);
3. Create a test case to test the `toStringByPayerName` method of the PaymentPresenter class
- When there are multiple payments, you need to sort by calling the `PaymentSortByPayer` class to sort, then build the string using the short description
Payment[] payments = new Payment[2]; Payment paypal = new PayPayl(4L, "Tamara Mowry", "tamara@mowry.com"); Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
payment[0] = paypal;
PaymentPresenter presenter = new PaymentPresenter(); String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
String actual = presenter.toString(payments); assertEquals(expected, actual);
4. Create a test case to test the `toStringById` method of the PaymentPresenter class
- 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
Payment[] payments = new Payment[2]; Payment paypal = new PayPayl(120L, "Tamara Mowry", "tamara@mowry.com"); Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
payment[0] = paypal;
PaymentPresenter presenter = new PaymentPresenter(); String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
String actual = presenter.toString(payments); assertEquals(expected, actual); ```