From 124ea2bad7017ec1d5918a7a341427d39893c5a9 Mon Sep 17 00:00:00 2001 From: jgiroso Date: Sun, 4 Jul 2021 00:30:17 -0400 Subject: [PATCH 1/2] Person Class Lab --- pom.xml | 12 ++++++++++++ .../java/com/zipcodewilmington/person/Person.java | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6d56659..d8f55a1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.zipcodewilmington person 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 15 + 15 + + + + junit diff --git a/src/main/java/com/zipcodewilmington/person/Person.java b/src/main/java/com/zipcodewilmington/person/Person.java index c12425f..22f8e56 100644 --- a/src/main/java/com/zipcodewilmington/person/Person.java +++ b/src/main/java/com/zipcodewilmington/person/Person.java @@ -8,28 +8,36 @@ public class Person { private int age; public Person() { + this.name = ""; + this.age = Integer.MAX_VALUE; } public Person(int age) { + setAge(age); } public Person(String name) { + setName(name); } public Person(String name, int age) { + setName(name); + setAge(age); } public void setName(String name) { + this.name = name; } public void setAge(int age) { + this.age = age; } public String getName() { - return null; + return name; } public Integer getAge() { - return null; + return age; } } From a2be2850b7b5e6f3d614b2f6e747b71806dc787b Mon Sep 17 00:00:00 2001 From: jgiroso Date: Sun, 4 Jul 2021 01:05:53 -0400 Subject: [PATCH 2/2] added 5 additional methods --- .../com/zipcodewilmington/person/Person.java | 45 +++++++++++++++ .../zipcodewilmington/person/TestPerson.java | 55 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/person/Person.java b/src/main/java/com/zipcodewilmington/person/Person.java index 22f8e56..5a76203 100644 --- a/src/main/java/com/zipcodewilmington/person/Person.java +++ b/src/main/java/com/zipcodewilmington/person/Person.java @@ -6,6 +6,11 @@ public class Person { private String name; private int age; + private String hairColor; + private String eyeColor; + private int height; + private int weight; + private String occupation; public Person() { this.name = ""; @@ -40,4 +45,44 @@ public String getName() { public Integer getAge() { return age; } + + public String getHairColor() { + return hairColor; + } + + public void setHairColor(String hairColor) { + this.hairColor = hairColor; + } + + public String getEyeColor() { + return eyeColor; + } + + public void setEyeColor(String eyeColor) { + this.eyeColor = eyeColor; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public String getOccupation() { + return occupation; + } + + public void setOccupation(String occupation) { + this.occupation = occupation; + } } diff --git a/src/test/java/com/zipcodewilmington/person/TestPerson.java b/src/test/java/com/zipcodewilmington/person/TestPerson.java index 59af3b2..ce790c3 100644 --- a/src/test/java/com/zipcodewilmington/person/TestPerson.java +++ b/src/test/java/com/zipcodewilmington/person/TestPerson.java @@ -95,4 +95,59 @@ public void testSetAge() { Integer actual = person.getAge(); Assert.assertEquals(expected, actual); } + @Test + public void testSetHairColor() { + //given + Person person = new Person(); + String expected = "brown"; + //when + person.setHairColor(expected); + //then + String actual = person.getHairColor(); + Assert.assertEquals(expected, actual); + } + @Test + public void testSetEyeColor() { + //given + Person person = new Person(); + String expected = "hazel"; + //when + person.setEyeColor(expected); + //then + String actual = person.getEyeColor(); + Assert.assertEquals(expected, actual); + } + @Test + public void testHeight() { + //given + Person person = new Person(); + int expected = 67; + //when + person.setHeight(expected); + //then + int actual = person.getHeight(); + Assert.assertEquals(expected, actual); + } + @Test + public void testWeight() { + //given + Person person = new Person(); + int expected = 155; + //when + person.setWeight(expected); + //then + int actual = person.getWeight(); + Assert.assertEquals(expected, actual); + } + @Test + public void testOccupation() { + //given + Person person = new Person(); + String expected = "software developer"; + //when + person.setOccupation(expected); + //then + String actual = person.getOccupation(); + Assert.assertEquals(expected, actual); + } }