Kaynağa Gözat

Section 1 Complete

shakila 8 yıl önce
ebeveyn
işleme
2e320d356d

+ 20
- 20
README.MD Dosyayı Görüntüle

@@ -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;

+ 8
- 0
pom.xml Dosyayı Görüntüle

@@ -7,6 +7,14 @@
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
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>

+ 47
- 0
src/main/java/com/zipcoder/payment/Check.java Dosyayı Görüntüle

@@ -0,0 +1,47 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+    long id;
5
+    String payerName;
6
+    String routingNumber;
7
+    String accountNumber;
8
+
9
+    public Check(){
10
+        id = 12345;
11
+        payerName = "Tia Mowry";
12
+        routingNumber = "987654321";
13
+        accountNumber = "0123456789";
14
+    }
15
+
16
+    public Long getId() {
17
+        return id;
18
+    }
19
+
20
+    public void setId(long id){
21
+    }
22
+
23
+    public String getPayerName() {
24
+        return payerName;
25
+    }
26
+
27
+    public void setPayerName(String payerName){
28
+    }
29
+
30
+    public String getShortDescription() {
31
+        return "Check" + getPayerName() + getAccountNumber() ;
32
+    }
33
+
34
+    public void setRoutingNumber(String routingNumber) {
35
+    }
36
+
37
+    public String getRoutingNumber() {
38
+        return routingNumber;
39
+    }
40
+
41
+    public void setAccountNumber(String accountNumber) {
42
+    }
43
+
44
+    public String getAccountNumber() {
45
+    return accountNumber;
46
+    }
47
+}

+ 57
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Dosyayı Görüntüle

@@ -0,0 +1,57 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment{
4
+    long id;
5
+    String payerName;
6
+    String number;
7
+    int expiredMonth;
8
+    int expiredYear;
9
+
10
+    public  CreditCard(){
11
+        id = 12345;
12
+        payerName = "Tia Mowry";
13
+        number = "4551";
14
+        expiredMonth = 10;
15
+        expiredYear = 2019;
16
+    }
17
+
18
+    public Long getId() {
19
+        return id;
20
+    }
21
+
22
+    public String getPayerName() {
23
+        return payerName;
24
+    }
25
+
26
+    public String getShortDescription() {
27
+        return "CC" + getPayerName() + getNumber() + getExpiredMonth() + "/" + getExpiredYear();
28
+    }
29
+
30
+
31
+    public void setId(long id) {
32
+    }
33
+
34
+    public void setPayerName(String payerName) {
35
+    }
36
+
37
+    public String getNumber(){
38
+        return number;
39
+    }
40
+
41
+    public void setNumber(String number){
42
+    }
43
+
44
+    public void setExpiredMonth(int expiredMonth) {
45
+    }
46
+
47
+    public int getExpiredMonth() {
48
+        return expiredMonth;
49
+    }
50
+
51
+    public void setExpiredYear(int expiredYear) {
52
+    }
53
+
54
+    public int getExpiredYear() {
55
+        return expiredYear;
56
+    }
57
+}

+ 38
- 0
src/main/java/com/zipcoder/payment/PayPal.java Dosyayı Görüntüle

@@ -0,0 +1,38 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment {
4
+        long id;
5
+        String payerName;
6
+        String email;
7
+
8
+    public PayPal(){
9
+        id = 12345;
10
+        payerName = "Tia Mowry";
11
+        email = "tia@mowry.com";
12
+    }
13
+
14
+    public Long getId() {
15
+        return id;
16
+    }
17
+
18
+    public String getPayerName() {
19
+        return payerName;
20
+    }
21
+
22
+    public String getShortDescription() {
23
+        return null;
24
+    }
25
+
26
+    public void setId(long id) {
27
+    }
28
+
29
+    public void setPayerName(String payerName) {
30
+    }
31
+
32
+    public void setEmail(String email) {
33
+    }
34
+
35
+    public String getEmail() {
36
+        return email;
37
+    }
38
+}

+ 13
- 0
src/main/java/com/zipcoder/payment/Payment.java Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+package com.zipcoder.payment;
2
+
3
+public interface Payment {
4
+
5
+    Long getId();
6
+
7
+    String getPayerName();
8
+
9
+    String getShortDescription();
10
+
11
+
12
+
13
+}

+ 53
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Dosyayı Görüntüle

@@ -0,0 +1,53 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class CheckTest {
8
+
9
+    @Test
10
+    public void getSetId() {
11
+        long id = 12345;
12
+        long expectedId = id;
13
+        Check check = new Check();
14
+        check.setId(id);
15
+        long actualId = check.getId();
16
+        assertEquals(expectedId, actualId);
17
+    }
18
+
19
+    @Test
20
+    public void getSetPayerName() {
21
+        String payerName = "Tia Mowry";
22
+        String expectedPayerName = payerName;
23
+        Check check = new Check();
24
+        check.setPayerName(payerName);
25
+        String actualPayerName = check.getPayerName();
26
+        assertEquals(expectedPayerName, actualPayerName);
27
+    }
28
+
29
+    @Test
30
+    public void getSetRoutingNumber(){
31
+        String routingNumber = "987654321";
32
+        String expectedRoutingNUmber = routingNumber;
33
+        Check check = new Check();
34
+        check.setRoutingNumber(routingNumber);
35
+        String actualRoutingNumber = check.getRoutingNumber();
36
+        assertEquals(expectedRoutingNUmber, actualRoutingNumber);
37
+    }
38
+
39
+    @Test
40
+    public void getSetAccountNumber(){
41
+        String accountNumber = "0123456789";
42
+        String expectedAccountNumber = accountNumber;
43
+        Check check = new Check();
44
+        check.setAccountNumber(accountNumber);
45
+        String actualAccountNumber = check.getAccountNumber();
46
+        assertEquals(expectedAccountNumber, actualAccountNumber);
47
+    }
48
+
49
+    @Test
50
+    public void getShortDescription() {
51
+
52
+    }
53
+}

+ 74
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+
9
+public class CreditCardTest {
10
+
11
+    @org.junit.Before
12
+    public void setUp() throws Exception {
13
+    }
14
+
15
+    @org.junit.After
16
+    public void tearDown() throws Exception {
17
+    }
18
+
19
+    @org.junit.Test
20
+    public void getSetIdTest() {
21
+        long id = 12345;
22
+        long expectedId = id;
23
+        CreditCard creditCard = new CreditCard();
24
+        creditCard.setId(id);
25
+        long actualId = creditCard.getId();
26
+        assertEquals(expectedId, actualId);
27
+    }
28
+
29
+    @Test
30
+    public void getSetPayerNameTest(){
31
+        String payerName = "Tia Mowry";
32
+        String expectedPayerName = payerName;
33
+        CreditCard creditCard = new CreditCard();
34
+        creditCard.setPayerName(payerName);
35
+        String actualPayerName = creditCard.getPayerName();
36
+        assertEquals(expectedPayerName, actualPayerName);
37
+    }
38
+
39
+
40
+    @org.junit.Test
41
+    public void getSetNumber() {
42
+    String number = "4551";
43
+    String expectedNumber = number;
44
+    CreditCard creditCard = new CreditCard();
45
+    creditCard.setNumber(number);
46
+    String actualNumber = creditCard.getNumber();
47
+    assertEquals(expectedNumber, actualNumber);
48
+    }
49
+
50
+    @Test
51
+    public void getSetExpiredMonth(){
52
+        int expiredMonth = 10;
53
+        int expectedExpiredMonth = expiredMonth;
54
+        CreditCard creditCard = new CreditCard();
55
+        creditCard.setExpiredMonth(expiredMonth);
56
+        int actualExpiredMonth = creditCard.getExpiredMonth();
57
+        assertEquals(expectedExpiredMonth, actualExpiredMonth);
58
+    }
59
+
60
+    @Test
61
+    public void getSetExpiredYear(){
62
+        int expiredYear = 2019;
63
+        int expectedExpiredYear = expiredYear;
64
+        CreditCard creditCard = new CreditCard();
65
+        creditCard.setExpiredYear(expiredYear);
66
+        int actualExpiredYear = creditCard.getExpiredYear();
67
+        assertEquals(expectedExpiredYear, actualExpiredYear);
68
+    }
69
+
70
+    @org.junit.Test
71
+    public void getShortDescription() {
72
+    }
73
+
74
+}

+ 42
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Dosyayı Görüntüle

@@ -0,0 +1,42 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PayPalTest {
8
+
9
+    @Test
10
+    public void getSetId() {
11
+        long id = 12345;
12
+        long expectedId = id;
13
+        PayPal payPal = new PayPal();
14
+        payPal.setId(id);
15
+        long actualId = payPal.getId();
16
+        assertEquals(expectedId, actualId);
17
+    }
18
+
19
+    @Test
20
+    public void getSetPayerName() {
21
+        String payerName = "Tia Mowry";
22
+        String expectedPayerName = payerName;
23
+        PayPal payPal = new PayPal();
24
+        payPal.setPayerName(payerName);
25
+        String actualPayerName = payPal.getPayerName();
26
+        assertEquals(expectedPayerName, actualPayerName);
27
+    }
28
+
29
+    @Test
30
+    public void getSetEmail(){
31
+        String email = "tia@mowry.com";
32
+        String expectedEmail = email;
33
+        PayPal payPal = new PayPal();
34
+        payPal.setEmail(email);
35
+        String actualEmail = payPal.getEmail();
36
+        assertEquals(expectedEmail, actualEmail);
37
+    }
38
+
39
+    @Test
40
+    public void getShortDescription() {
41
+    }
42
+}