Roy hace 6 años
padre
commit
09f8a22bd1

+ 41
- 0
pom.xml Ver fichero

@@ -0,0 +1,41 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcodewilmington.assessment1</groupId>
8
+    <artifactId>question1</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <properties>
11
+        <maven.compiler.source>1.8</maven.compiler.source>
12
+        <maven.compiler.target>1.8</maven.compiler.target>
13
+    </properties>
14
+    <dependencies>
15
+        <dependency>
16
+            <groupId>junit</groupId>
17
+            <artifactId>junit</artifactId>
18
+            <version>4.12</version>
19
+        </dependency>
20
+        <!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-core -->
21
+        <dependency>
22
+            <groupId>com.j256.ormlite</groupId>
23
+            <artifactId>ormlite-core</artifactId>
24
+            <version>4.48</version>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>com.h2database</groupId>
28
+            <artifactId>h2</artifactId>
29
+            <version>1.4.197</version>
30
+        </dependency>
31
+
32
+        <!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-jdbc -->
33
+        <dependency>
34
+            <groupId>com.j256.ormlite</groupId>
35
+            <artifactId>ormlite-jdbc</artifactId>
36
+            <version>4.48</version>
37
+        </dependency>
38
+    </dependencies>
39
+
40
+
41
+</project>

+ 19
- 0
question1.iml Ver fichero

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+    <orderEntry type="library" name="Maven: com.j256.ormlite:ormlite-core:4.48" level="project" />
16
+    <orderEntry type="library" name="Maven: com.h2database:h2:1.4.197" level="project" />
17
+    <orderEntry type="library" name="Maven: com.j256.ormlite:ormlite-jdbc:4.48" level="project" />
18
+  </component>
19
+</module>

+ 4
- 0
src/main/java/CheckPerson.java Ver fichero

@@ -0,0 +1,4 @@
1
+public interface CheckPerson {
2
+
3
+    boolean test(Person p);
4
+}

+ 60
- 0
src/main/java/Group.java Ver fichero

@@ -0,0 +1,60 @@
1
+import java.text.ParseException;
2
+import java.time.LocalDate;
3
+import java.time.format.DateTimeFormatter;
4
+import java.util.ArrayList;
5
+import java.util.Formatter;
6
+import java.util.List;
7
+import java.util.Scanner;
8
+
9
+public class Group {
10
+
11
+    Person person ;
12
+    Scanner in = new Scanner(System.in);
13
+
14
+
15
+    public List<Person> populateGroup(List<Person> persons, int number){
16
+        for (int i=0; i<number; i++){
17
+            System.out.println("Enter name:");
18
+            String name = in.nextLine();
19
+
20
+            System.out.println("Enter birthday in yyyy-MMM-dd");
21
+            String date  = in.nextLine();
22
+            DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MMM-d");
23
+            LocalDate birthDay = (LocalDate.parse(date, dateFormat));
24
+
25
+            System.out.println("Enter sex:");
26
+            Person.Sex sex = Person.Sex.valueOf(in.nextLine().toUpperCase());
27
+
28
+            System.out.println("enter email");
29
+            String email = in.nextLine();
30
+            person = new Person(name, birthDay, sex, email);
31
+            persons.add(person);
32
+        }
33
+        return persons;
34
+    }
35
+
36
+    public static void printPersonsWithinAgeRange(List<Person> roster, int low, int high) {
37
+        for (Person p : roster) {
38
+            if (low <= p.getAge() && p.getAge() < high) {
39
+                p.printPerson();
40
+            }
41
+        }
42
+    }
43
+
44
+    public static void printPersons(List<Person> roster, CheckPerson tester) {
45
+        for (Person p : roster) {
46
+            if (tester.test(p)) {
47
+                p.printPerson();
48
+            }
49
+        }
50
+    }
51
+
52
+    public static String printingPersons(List<Person> roster, CheckPerson tester) {
53
+        for (Person p : roster) {
54
+            if (tester.test(p)) {
55
+                return p.getName() +" "+p.getEmailAddress();
56
+            }
57
+        }
58
+        return null;
59
+    }
60
+}

+ 36
- 0
src/main/java/MainApplication.java Ver fichero

@@ -0,0 +1,36 @@
1
+import java.util.ArrayList;
2
+import java.util.Scanner;
3
+
4
+public class MainApplication {
5
+
6
+    public static void main(String[] args){
7
+
8
+        Person person;
9
+        Group group = new Group();
10
+        ArrayList<Person> persons = new ArrayList<>();
11
+        Scanner in = new Scanner(System.in);
12
+        boolean loop = true;
13
+
14
+
15
+        while(loop) {
16
+            System.out.println("Enter command 1 to add to group, 2");
17
+            int cmd = in.nextInt();
18
+
19
+            switch (cmd) {
20
+
21
+                case 1:
22
+                    System.out.println("Enter how many people to add");
23
+                    int num = in.nextInt();
24
+                    group.populateGroup(persons, num);
25
+                    break;
26
+                case 2:
27
+                    Group.printPersons(persons, per -> per.getGender() == Person.Sex.FEMALE);
28
+                    break;
29
+                case 3:
30
+                    loop = false;
31
+                    break;
32
+            }
33
+        }
34
+
35
+    }
36
+}

+ 61
- 0
src/main/java/Person.java Ver fichero

@@ -0,0 +1,61 @@
1
+import java.time.LocalDate;
2
+//import java.util.
3
+public class Person {
4
+
5
+    public enum Sex {
6
+        MALE, FEMALE
7
+    }
8
+
9
+    String name;
10
+    LocalDate birthday;
11
+    Sex gender;
12
+    String emailAddress;
13
+
14
+    public Person(String name, LocalDate birthday, Sex gender, String emailAddress){
15
+        this.name = name;
16
+        //this.birthday = birthday;
17
+        this.gender = gender;
18
+        this.emailAddress = emailAddress;
19
+
20
+    }
21
+
22
+    public String getName() {
23
+        return name;
24
+    }
25
+
26
+    public void setName(String name) {
27
+        this.name = name;
28
+    }
29
+
30
+    public LocalDate getBirthday() {
31
+        return birthday;
32
+    }
33
+
34
+    public void setBirthday(LocalDate birthday) {
35
+        this.birthday = birthday;
36
+    }
37
+
38
+    public int getAge() {
39
+        return LocalDate.now().getYear() - birthday.getYear();
40
+    }
41
+
42
+    public Sex getGender() {
43
+        return gender;
44
+    }
45
+
46
+    public void setGender(Sex gender) {
47
+        this.gender = gender;
48
+    }
49
+
50
+    public String getEmailAddress() {
51
+        return emailAddress;
52
+    }
53
+
54
+    public void setEmailAddress(String emailAddress) {
55
+        this.emailAddress = emailAddress;
56
+    }
57
+
58
+    public void printPerson() {
59
+        System.out.println(this.getName() +" "+ this.emailAddress);
60
+    }
61
+}

+ 40
- 0
src/test/java/GroupTest.java Ver fichero

@@ -0,0 +1,40 @@
1
+import org.junit.Assert;
2
+import org.junit.Before;
3
+import org.junit.Test;
4
+
5
+import java.time.LocalDate;
6
+import java.util.ArrayList;
7
+
8
+import static org.junit.Assert.*;
9
+
10
+public class GroupTest {
11
+
12
+    Person person;
13
+    Group group;
14
+    LocalDate birthDay;
15
+
16
+    @Before
17
+    public void thisIsAtest() {
18
+        birthDay = LocalDate.of(1991,9,20);
19
+        person = new Person("roy", birthDay, Person.Sex.MALE, "reero@ymail.com");
20
+    }
21
+
22
+    @Test
23
+    public void printPersonTest(){
24
+        String actual = "roy reero@ymail.com";
25
+        String expected = person.getName() +" "+ person.emailAddress;
26
+        Assert.assertEquals(actual, expected);
27
+    }
28
+
29
+    @Test
30
+    public void printPersons(){
31
+        ArrayList<Person> arr = new ArrayList<>();
32
+        arr.add(person);
33
+        arr.add(new Person("karen", birthDay, Person.Sex.FEMALE, "ewhubwjn@ymail.com"));
34
+        String actual = "karen ewhubwjn@ymail.com";
35
+        String expected = Group.printingPersons(arr, per -> per.getGender() == Person.Sex.FEMALE);
36
+        Assert.assertEquals(actual, expected);
37
+    }
38
+
39
+
40
+}

+ 34
- 0
src/test/java/PersonTest.java Ver fichero

@@ -0,0 +1,34 @@
1
+import org.junit.Assert;
2
+import org.junit.Before;
3
+import org.junit.Test;
4
+
5
+import java.time.LocalDate;
6
+
7
+import static org.junit.Assert.*;
8
+
9
+public class PersonTest {
10
+    Person person;
11
+    LocalDate birthDay;
12
+
13
+    @Before
14
+    public void thisIsAtest() {
15
+        birthDay = LocalDate.of(1991,9,20);
16
+        person = new Person("roy", birthDay, Person.Sex.MALE, "reero@ymail.com");
17
+    }
18
+
19
+    @Test
20
+    public void getAgeTest(){
21
+        person.setBirthday(birthDay);
22
+        int actual = 27;
23
+        int expected = person.getAge();
24
+        Assert.assertEquals(actual, expected);
25
+    }
26
+
27
+    @Test
28
+    public void getSexTest(){
29
+        Person.Sex actual = Person.Sex.MALE;
30
+        Person.Sex expected = person.getGender();
31
+        Assert.assertEquals(actual, expected);
32
+    }
33
+}
34
+

BIN
target/classes/CheckPerson.class Ver fichero


BIN
target/classes/Group.class Ver fichero


BIN
target/classes/MainApplication.class Ver fichero


BIN
target/classes/Person$Sex.class Ver fichero


BIN
target/classes/Person.class Ver fichero


BIN
target/test-classes/GroupTest.class Ver fichero


BIN
target/test-classes/PersonTest.class Ver fichero