Yesoda Sanka 7 gadus atpakaļ
vecāks
revīzija
9038157afc

Binārs
.DS_Store Parādīt failu


+ 1
- 1
README.MD Parādīt failu

@@ -72,7 +72,7 @@ Note: You may use the String/Long compareTo methods in your code
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 8 implements Comparator<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

+ 14
- 0
pom.xml Parādīt failu

@@ -7,6 +7,20 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>junit</groupId>
19
+            <artifactId>junit</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
     <properties>
11 25
         <maven.compiler.source>1.8</maven.compiler.source>
12 26
         <maven.compiler.target>1.8</maven.compiler.target>

+ 93
- 0
src/main/java/com/zipcoder/payment/Check.java Parādīt failu

@@ -0,0 +1,93 @@
1
+package com.zipcoder.payment;
2
+
3
+public   class Check implements Payment  {
4
+
5
+    /*
6
+    Create a `Check` class which implements the `Payment` interface
7
+3. Add the required methods from the interface
8
+4. Add getter and setter test for an id
9
+  - Add a Long id field
10
+  - Add a getter and setter method to make the test pass
11
+5. Repeat step 4 for the following fields:
12
+  - String payerName
13
+  - String routing number
14
+  - String accountNumber
15
+6. Implement the `getShortDescription` to return `Check [payerName] ***[last 4 digit of the account]`
16
+  - ex: `Check Tia Mowry ***4551`
17
+7. You may create any type of constructor or methods that will with this lab
18
+
19
+     */
20
+
21
+    long id;
22
+    String payerName;
23
+
24
+    String routingNumber;
25
+    String accountNumber;
26
+
27
+
28
+    public Check() {
29
+    }
30
+
31
+    public Check(long id, String payerName, String routingNumber, String accountNumber) {
32
+        this.id = id;
33
+        this.payerName = payerName;
34
+        this.routingNumber = routingNumber;
35
+        this.accountNumber = accountNumber;
36
+    }
37
+
38
+    public long getId() {
39
+        return id;
40
+    }
41
+
42
+    public void setId(long id) {
43
+        this.id = id;
44
+    }
45
+
46
+    public String getpayerName() {
47
+        return payerName;
48
+    }
49
+
50
+    public void setPayerName(String payerName) {
51
+        this.payerName = payerName;
52
+    }
53
+
54
+    public String getRoutingNumber() {
55
+        return routingNumber;
56
+    }
57
+
58
+    public void setRoutingNumber(String routingNumber) {
59
+        this.routingNumber = routingNumber;
60
+    }
61
+
62
+    public String getAccountNumber() {
63
+        return accountNumber;
64
+    }
65
+
66
+    public void setAccountNumber(String accountNumber) {
67
+        this.accountNumber = accountNumber;
68
+    }
69
+    public String getLastfourAccountNumber() {
70
+        String str = "";
71
+        String acctNo = this.accountNumber.toString();
72
+        if (acctNo.length() > 4) {
73
+            str = acctNo.substring(acctNo.length() - 4);
74
+        } else {
75
+            str = acctNo;
76
+        }
77
+
78
+         return str;
79
+
80
+    }
81
+    @Override
82
+
83
+    public String getShortDescription() {
84
+        return "Check " + this.payerName + " ***" + this.getLastfourAccountNumber() ;
85
+    }
86
+
87
+
88
+    @Override
89
+    public int compareTo(Payment other) {
90
+        return this.getShortDescription() .compareTo(other.getShortDescription() );
91
+
92
+    }
93
+}

+ 102
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Parādīt failu

@@ -0,0 +1,102 @@
1
+package com.zipcoder.payment;
2
+
3
+  public  class CreditCard implements Payment  {
4
+
5
+      /*
6
+                Create a `CreditCard` class which implements the `Payment` interface
7
+               3. Add the required methods from the interface
8
+               4. Add getter and setter test for an id
9
+                - Add a Long id field
10
+               - Add a getter and setter method to make the test pass
11
+               5. Repeat step 4 for the following fields:
12
+                - String payerName
13
+               - String number
14
+                - int expiredMonth
15
+                - int expiredYear
16
+               6  Implement the `getShortDescription` to return `CC
17
+                 [payerName] [last 4 digit of the number] [expiredMonth]/[expiredYear]`
18
+               - ex: `CC Tia Mowry 4551 10/2019`
19
+              7. You may create any type of constructor or methods that will with this lab
20
+                */
21
+        private   long pid;
22
+      private  String payerName;
23
+      private  String number;
24
+     private  int expireMonth;
25
+     private  int expiredYear;
26
+
27
+
28
+
29
+      public CreditCard() {
30
+      }
31
+
32
+      public CreditCard(long pid, String payerName, String number, int expireMonth, int expiredYear) {
33
+          this.pid = pid;
34
+          this.payerName = payerName;
35
+          this.number = number;
36
+          this.expireMonth = expireMonth;
37
+          this.expiredYear = expiredYear;
38
+      }
39
+      public long getPid() {
40
+          return pid;
41
+      }
42
+
43
+      public void setPid(long pid) {
44
+          this.pid = pid;
45
+      }
46
+
47
+
48
+      public String getNumber() {
49
+          return number;
50
+      }
51
+
52
+      public void setNumber(String number) {
53
+          this.number = number;
54
+      }
55
+
56
+      public int getExpireMonth() {
57
+          return expireMonth;
58
+      }
59
+
60
+      public void setExpireMonth(int expireMonth) {
61
+          this.expireMonth = expireMonth;
62
+      }
63
+
64
+      public int getExpiredYear() {
65
+          return expiredYear;
66
+      }
67
+
68
+      public void setExpiredYear(int expiredYear) {
69
+          this.expiredYear = expiredYear;
70
+      }
71
+     @Override
72
+     public long getId(){
73
+          return pid;
74
+     }
75
+      @Override
76
+      public String getpayerName(){
77
+        return payerName;
78
+
79
+      }
80
+      public void setPayerName()
81
+      {
82
+          this.payerName =payerName;
83
+      }
84
+ @Override
85
+      public String getShortDescription() {
86
+          return "CreditCard{" +
87
+                  "payerName =" + this.payerName  +
88
+                  ", payerNumber='" + this.number + '\'' +
89
+                  ", expireMonth=" + this.expireMonth +
90
+                  ", expiredYear=" + this.expiredYear +
91
+                  '}';
92
+      }
93
+
94
+      @Override
95
+      public int compareTo(Payment other) {
96
+          return this.getShortDescription().compareTo(other.getShortDescription());
97
+
98
+
99
+      }
100
+
101
+
102
+      }

+ 78
- 0
src/main/java/com/zipcoder/payment/PayPal.java Parādīt failu

@@ -0,0 +1,78 @@
1
+package com.zipcoder.payment;
2
+import java.util.Comparator;
3
+
4
+public class PayPal implements  Payment  {
5
+    /*
6
+    1. Create a `PayPalTest` test class
7
+2. Create a `PayPal` class which implements the `Payment` interface
8
+3. Add the required methods from the interface
9
+4. Add getter and setter test for an id
10
+  - Add a Long id field
11
+  - Add a getter and setter method to make the test pass
12
+5. Repeat step 4 for the following fields:
13
+  - String payerName
14
+  - String email
15
+6. Implement the `getShortDescription` to return `Paypal [payerName] [email]`
16
+  - ex: `Paypal Tia Mowry tia@mowry.com`
17
+7. You may create any type of constructor or methods that will with this lab
18
+
19
+     */
20
+
21
+    long id;
22
+    String payerName;
23
+    String email;
24
+
25
+
26
+    public PayPal(long id, String payerName, String email) {
27
+        this.id = id;
28
+        this.payerName = payerName;
29
+        this.email = email;
30
+    }
31
+
32
+    public long getId() {
33
+        return id;
34
+    }
35
+
36
+    @Override
37
+    public String getpayerName() {
38
+        return null;
39
+    }
40
+
41
+    @Override
42
+    public String getShortDescription() {
43
+        //`Paypal [payerName] [email]`
44
+        return "Paypal "+ this.payerName +" " +this.email ;
45
+    }
46
+
47
+    public void setId(long id) {
48
+        this.id = id;
49
+    }
50
+
51
+    public String getPayerName() {
52
+        return payerName;
53
+    }
54
+
55
+    public void setPayerName(String payerName) {
56
+        this.payerName = payerName;
57
+    }
58
+
59
+    public String getEmail() {
60
+        return email;
61
+    }
62
+
63
+    public void setEmail(String email) {
64
+        this.email = email;
65
+    }
66
+
67
+
68
+    @Override
69
+    public int compareTo(Payment other) {
70
+        return this.getShortDescription().compareTo(other.getShortDescription());
71
+
72
+    }
73
+
74
+
75
+}
76
+
77
+
78
+

+ 19
- 0
src/main/java/com/zipcoder/payment/Payment.java Parādīt failu

@@ -0,0 +1,19 @@
1
+package com.zipcoder.payment;
2
+
3
+/*Create a `Payment` interface
4
+  - The class should define a `getId()` method which returns a Long
5
+        - The class should define a `getPayerName()` method which returns a String
6
+        - The class should define a `getShortDescription` method which returns a String
7
+
8
+*/
9
+public interface Payment extends Comparable<Payment>{
10
+
11
+   public  long getId();
12
+
13
+   public  String  getpayerName();
14
+
15
+   public  String getShortDescription();
16
+
17
+}
18
+
19
+

+ 39
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Parādīt failu

@@ -1,6 +1,45 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.Collections;
6
+
3 7
 public class PaymentPresenter {
4 8
 
9
+    public PaymentPresenter() {
10
+
11
+    }
12
+    //String actual = presenter.toString(payments)
13
+
14
+    public String toString(ArrayList <Payment> payments ) {
15
+        StringBuilder sb=new StringBuilder() ;
16
+        for(Payment p:payments  ){
17
+           sb.append(p.getShortDescription() ) ;
18
+           sb.append("\n");
19
+        }
20
+        return sb.toString();
21
+    }
22
+
23
+     /*
24
+     When there are multiple payments, you need to sort it first, then build the string using the short description
25
+
26
+      */
27
+     public String  toSort(Payment[] payments  ){
28
+         ArrayList<Payment> arrayList = new ArrayList<Payment>(Arrays.asList(payments));
29
+         Collections.sort(arrayList, new PaymentSortByPayer() );
30
+
31
+         return toString(arrayList );
32
+
33
+     }
34
+     /*
35
+      When there are multiple payments, you need to sort by calling the `PaymentSortByPayer`
36
+      class to sort, then build the string using the short description
37
+      */
38
+      public String toStringByPayerName(Payment[] payments ){
39
+          ArrayList<Payment> arrayList = new ArrayList<Payment>(Arrays.asList(payments));
40
+          Collections.sort(arrayList, new PaymentSortByPayer()  );
41
+
42
+          return toString(arrayList ) ;
43
+      }
5 44
 
6 45
 }

+ 25
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Parādīt failu

@@ -0,0 +1,25 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+import java.util.function.Function;
5
+import java.util.function.ToDoubleFunction;
6
+import java.util.function.ToIntFunction;
7
+import java.util.function.ToLongFunction;
8
+
9
+/*
10
+5. Create a new `PaymentSortByPayer` class which implements `java.util.Comparator`
11
+  - This class will sort by payer name
12
+  - `public class 8 implements Comparator<Payment>`
13
+ */
14
+
15
+public class PaymentSortByPayer implements Comparator<Payment> {
16
+
17
+    @Override
18
+    public int  compare(Payment p1,Payment p2)
19
+    {
20
+        return p1.getShortDescription() .compareTo(p2.getShortDescription() ) ;
21
+
22
+    }
23
+
24
+
25
+}

+ 2
- 0
src/test/java/CheckTest.java Parādīt failu

@@ -0,0 +1,2 @@
1
+public class CheckTest {
2
+}

+ 2
- 0
src/test/java/CreditCardTest.java Parādīt failu

@@ -0,0 +1,2 @@
1
+public class CreditCardTest {
2
+}

+ 74
- 0
src/test/java/PaymentPresenterTest.java Parādīt failu

@@ -0,0 +1,74 @@
1
+
2
+import com.zipcoder.payment.Check;
3
+import com.zipcoder.payment.PayPal;
4
+import com.zipcoder.payment.Payment;
5
+import com.zipcoder.payment.PaymentPresenter;
6
+import org.junit.Assert;
7
+import org.junit.Test;
8
+
9
+import java.util.ArrayList;
10
+import java.util.Arrays;
11
+
12
+
13
+/*
14
+ Create a test case to test the `toString` method of the PaymentPresenter class
15
+  - When there is no payment
16
+ */
17
+public class PaymentPresenterTest {
18
+
19
+    @Test
20
+    public void testToString() {
21
+        //Payment[] payments = new Payment[0];
22
+        ArrayList <Payment> payments=new ArrayList<>();
23
+        PaymentPresenter presenter = new PaymentPresenter();
24
+        String expected = "";
25
+
26
+        String actual = presenter.toString(payments);
27
+
28
+        Assert.assertEquals(expected, actual);
29
+
30
+
31
+    }
32
+    //When there are multiple payments, you need to sort it first, then build the string using the short description
33
+
34
+    @Test
35
+    public void testSort(){
36
+        Payment[] payments = new Payment[2];
37
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
38
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
39
+
40
+        payments[0] = paypal;
41
+        payments[1] = check;
42
+
43
+        PaymentPresenter presenter = new PaymentPresenter();
44
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
45
+         String actual=presenter.toSort(payments);
46
+
47
+        Assert .assertEquals(expected, actual);
48
+
49
+    }
50
+    /*
51
+    Create a test case to test the `toStringByPayerName` method of the PaymentPresenter class
52
+    - When there are multiple payments, you need to sort by calling the `PaymentSortByPayer`
53
+    class to sort, then build the string using the short description
54
+
55
+     */
56
+
57
+     @Test
58
+    public void toStringByPayerName(){
59
+         Payment[] payments = new Payment[2];
60
+         Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
61
+         Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
62
+
63
+         payments[0] = paypal;
64
+         payments[1] = check;
65
+
66
+         PaymentPresenter presenter = new PaymentPresenter();
67
+         String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
68
+
69
+         String actual = presenter.toStringByPayerName(payments);
70
+         Assert . assertEquals(expected, actual);
71
+
72
+
73
+     }
74
+}

+ 2
- 0
src/test/java/PaypalTest.java Parādīt failu

@@ -0,0 +1,2 @@
1
+public class PaypalTest {
2
+}

+ 6
- 0
src/test/java/com/zipcoder/payment/PaymentPresentTest.java Parādīt failu

@@ -0,0 +1,6 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PaymentPresentTest {
4
+
5
+
6
+}