From 3e736e1be013471aa1c32f2ddeaeb93beed51482 Mon Sep 17 00:00:00 2001 From: Dee Date: Sat, 3 Jul 2021 18:44:16 -0400 Subject: [PATCH 1/2] the default constructer fixed --- pom.xml | 12 ++++++++++++ .../com/zipcodewilmington/person/Person.java | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 6d56659..c87f792 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.zipcodewilmington person 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 14 + 14 + + + + junit diff --git a/src/main/java/com/zipcodewilmington/person/Person.java b/src/main/java/com/zipcodewilmington/person/Person.java index c12425f..87aa514 100644 --- a/src/main/java/com/zipcodewilmington/person/Person.java +++ b/src/main/java/com/zipcodewilmington/person/Person.java @@ -8,28 +8,37 @@ public class Person { private int age; public Person() { + this.name = ""; + this.age = Integer.MAX_VALUE; } public Person(int age) { + this.age = age; } public Person(String name) { + this.name = name; } public Person(String name, int age) { + this.name = name; + this.age = age; } - public void setName(String name) { + public void setName(String newName) { + this.name = newName; } - public void setAge(int age) { + public void setAge(int newAge) { + this.age = newAge; } public String getName() { - return null; + + return name; } public Integer getAge() { - return null; + return age; } } From 43eda7f3c24d99c919e2754e5d0fc91d57fafc1e Mon Sep 17 00:00:00 2001 From: Dee Date: Sun, 4 Jul 2021 11:57:48 -0400 Subject: [PATCH 2/2] added methods and tests for Person --- .../com/zipcodewilmington/person/Person.java | 31 +++++++++++++ .../zipcodewilmington/person/TestPerson.java | 45 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/person/Person.java b/src/main/java/com/zipcodewilmington/person/Person.java index 87aa514..54a3f30 100644 --- a/src/main/java/com/zipcodewilmington/person/Person.java +++ b/src/main/java/com/zipcodewilmington/person/Person.java @@ -4,8 +4,10 @@ * Created by leon on 2/12/18. */ public class Person { + private Double gpa; private String name; private int age; + private Integer height; public Person() { this.name = ""; @@ -23,6 +25,20 @@ public Person(String name) { public Person(String name, int age) { this.name = name; this.age = age; + + } + + public Person(String name, int age, Integer height) { + this.name = name; + this.age = age; + this.height = height; + } + + public Person(String name, Integer age, Integer height, Double gpa) { + this.name = name; + this.age = age; + this.height = height; + this.gpa = gpa; } public void setName(String newName) { @@ -41,4 +57,19 @@ public String getName() { public Integer getAge() { return age; } + + + + public Integer getHeight() { + return height; + } + + + public void setHeight(Integer height) { + this.height = height; + } + + public Double getGPA() { + return gpa; + } } diff --git a/src/test/java/com/zipcodewilmington/person/TestPerson.java b/src/test/java/com/zipcodewilmington/person/TestPerson.java index 59af3b2..04b71c9 100644 --- a/src/test/java/com/zipcodewilmington/person/TestPerson.java +++ b/src/test/java/com/zipcodewilmington/person/TestPerson.java @@ -95,4 +95,49 @@ public void testSetAge() { Integer actual = person.getAge(); Assert.assertEquals(expected, actual); } + + @Test + public void testGetHeight() { + //Given + Integer expectedAge =25; + String expectedName = "Dione"; + Integer expectedHeight = 68; + + //When + Person person = new Person(expectedName, expectedAge, expectedHeight); + + //Then + Integer actual = person.getHeight(); + Assert.assertEquals(expectedHeight, actual); + } + + @Test + public void testSetHeight() { + //Given + Person person = new Person(); + Integer expected = 70; + + //When + person.setHeight(expected); + + //Then + Integer actual = person.getHeight(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetGPA() { + //Given + Integer expectedAge =25; + String expectedName = "Dione"; + Integer expectedHeight = 68; + Double expectedGPA = 3.8; + + //When + Person testperson = new Person(expectedName,expectedAge,expectedHeight, expectedGPA); + + //Then + Double actual = testperson.getGPA(); + Assert.assertEquals(expectedGPA, actual); + } }