Bläddra i källkod

initial commit

Froilan Miranda 6 år sedan
incheckning
45c1e51e0a
6 ändrade filer med 282 tillägg och 0 borttagningar
  1. 115
    0
      .gitignore
  2. 30
    0
      Person.java
  3. 65
    0
      PersonHandler.java
  4. 61
    0
      PersonHandlerTest.java
  5. 11
    0
      README.md
  6. 0
    0
      package.bluej

+ 115
- 0
.gitignore Visa fil

@@ -0,0 +1,115 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/

+ 30
- 0
Person.java Visa fil

@@ -0,0 +1,30 @@
1
+ 
2
+
3
+/**
4
+ * Created by leon on 1/24/18.
5
+ */
6
+public class Person {
7
+    private final String firstName;
8
+    private final String lastName;
9
+
10
+    public Person(String firstName, String lastName) {
11
+        this.firstName = firstName;
12
+        this.lastName = lastName;
13
+    }
14
+
15
+    public String getFirstName() {
16
+        return firstName;
17
+    }
18
+
19
+    public String getLastName() {
20
+        return lastName;
21
+    }
22
+
23
+    @Override
24
+    public String toString() {
25
+        return new StringBuilder()
26
+                .append("\nMy first name is " + firstName)
27
+                .append("\nMy last name is " + lastName)
28
+                .toString();
29
+    }
30
+}

+ 65
- 0
PersonHandler.java Visa fil

@@ -0,0 +1,65 @@
1
+ 
2
+
3
+/**
4
+ * Created by leon on 1/24/18.
5
+ */
6
+public class PersonHandler {
7
+    private final Person[] personArray;
8
+
9
+    public PersonHandler(Person[] personArray) {
10
+        this.personArray = personArray;
11
+    }
12
+
13
+    public String whileLoop() {
14
+        String result = "";
15
+        // assume there is a `counter`
16
+        // while `counter` is less than length of array
17
+            // begin loop
18
+
19
+                // use `counter` to identify the `current Person` in the array
20
+                // get `string Representation` of `currentPerson`
21
+                // append `stringRepresentation` to `result` variable
22
+
23
+            // end loop
24
+        return result;
25
+    }
26
+
27
+
28
+
29
+    public String forLoop() {
30
+        String result = "";
31
+        // identify initial value
32
+        // identify terminal condition
33
+        // identify increment
34
+
35
+        // use the above clauses to declare for-loop signature
36
+            // begin loop
37
+                // use `counter` to identify the `current Person` in the array
38
+                // get `string Representation` of `currentPerson`
39
+                // append `stringRepresentation` to `result` variable
40
+            // end loop
41
+
42
+        return result;
43
+    }
44
+
45
+
46
+
47
+    public String forEachLoop() {
48
+        String result = "";
49
+        // identify array's type
50
+        // identify array's variable-name
51
+
52
+        // use the above discoveries to declare for-each-loop signature
53
+            // begin loop
54
+                // get `string Representation` of `currentPerson`
55
+                // append `stringRepresentation` to `result` variable
56
+            // end loop
57
+
58
+        return result;
59
+    }
60
+
61
+
62
+    public Person[] getPersonArray() {
63
+        return personArray;
64
+    }
65
+}

+ 61
- 0
PersonHandlerTest.java Visa fil

@@ -0,0 +1,61 @@
1
+ 
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+/**
8
+ * Created by leon on 1/24/18.
9
+ */
10
+public class PersonHandlerTest {
11
+    PersonHandler personHandler;
12
+    private String expected;
13
+
14
+    @Before
15
+    public void setup() {
16
+        // : Given
17
+        Person person1 = new Person("Leon", "Hunter");
18
+        Person person2 = new Person("Tariq", "Hook");
19
+        Person person3 = new Person("Dolio", "Durant");
20
+        Person[] personArray = {person1, person2, person3};
21
+
22
+        this.personHandler = new PersonHandler(personArray);
23
+        this.expected = "\nMy first name is Leon\n" +
24
+                "My last name is Hunter\n" +
25
+                "My first name is Tariq\n" +
26
+                "My last name is Hook\n" +
27
+                "My first name is Dolio\n" +
28
+                "My last name is Durant";
29
+    }
30
+
31
+    @Test
32
+    public void testWhileLoop() {
33
+        // : When
34
+        String actual = personHandler.whileLoop();
35
+
36
+        // : Then
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+
41
+    @Test
42
+    public void testForLoop() {
43
+        // : When
44
+        String actual = personHandler.forLoop();
45
+
46
+        // : Then
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+
50
+
51
+    @Test
52
+    public void testForEachLoop() {
53
+        // : When
54
+        String actual = personHandler.forEachLoop();
55
+
56
+        // : Then
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+
61
+}

+ 11
- 0
README.md Visa fil

@@ -0,0 +1,11 @@
1
+# Iterating an array of `Person` objects
2
+* **Objective:**
3
+    * To concatenate the details of `Person` objects by iterating an array  
4
+
5
+* **Purpose:**
6
+    * To demonstrate practical understanding of `while`, `for`, and `for each` loops.
7
+
8
+* **Getting started:**
9
+    * The [PersonHandler](https://github.com/Zipcoder/CR-MesoLabs-Loops-PersonDetails/blob/master/src/main/java/com/zipcodewilmington/PersonHandler.java) class has 3 [method stubs](https://en.wikipedia.org/wiki/Method_stub) to be completed.
10
+        * The methods contain line-by-line comments to guide you through the process.
11
+    * Ensure all tests cases pass successfully.

+ 0
- 0
package.bluej Visa fil