Skip to content

Feat: Created Chigazo's Lesson 16 Custom {Class}, Custom {Class} Exception, and {Class}Test; #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN Sep 26, 2024
05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 27, 2024
5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN Sep 30, 2024
56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 1, 2024
8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 2, 2024
4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 3, 2024
48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 5, 2024
1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 7, 2024
3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 9, 2024
712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 11, 2024
5db7413
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 11, 2024
5096f8e
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 12, 2024
09341aa
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 14, 2024
a8f634e
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 15, 2024
b643a4c
feat: created chigazograham.json file
Oct 16, 2024
cae2152
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 16, 2024
68ccb5f
fix: deleted lesson_09 content from main;
Oct 16, 2024
7d4f86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 16, 2024
473eb98
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 17, 2024
1d19106
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 17, 2024
bba5af5
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 18, 2024
a51c852
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 19, 2024
8a39fcc
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 21, 2024
ac98745
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 22, 2024
eade00f
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 23, 2024
bf252ad
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 23, 2024
955b86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 25, 2024
b6f63bd
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 28, 2024
22db65b
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 28, 2024
d5eff9e
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 28, 2024
2a09493
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 29, 2024
33e9bbc
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 30, 2024
f6f3267
Merge branch 'code-differently:main' into main
A1-4U2T1NN Oct 30, 2024
44faa1c
feat: added 7 member variables of 5 different types; added Person fun…
Oct 31, 2024
72c5d80
feat: created framework for PersonTest; added try catch statement to …
Oct 31, 2024
ad7ec4c
Merge branch 'code-differently:main' into lesson_16
A1-4U2T1NN Nov 1, 2024
78efa0f
feat: added .person to the package; added <String> to ArrayList innst…
Nov 1, 2024
70a83f0
Merge branch 'code-differently:main' into lesson_16
A1-4U2T1NN Nov 1, 2024
25a65dd
fix: ran ./gradlew spotlessapply to correct formating mistakes;
Nov 1, 2024
1c83b51
Merge branch 'lesson_16' of https://github.com/A1-4U2T1NN/code-differ…
Nov 1, 2024
6765a0b
fix: ran ./gradlew :objects_app:spotlessApply to correct formating mi…
Nov 1, 2024
a2e36d3
fix: changed IllegalArgumentException to custom PersonIsBaldException;
Nov 1, 2024
5d47096
fix: ran ./gradlew :objects:spotlessApply to correct formating mistakes;
Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.codedifferently.lesson16.person;

import java.util.ArrayList;

public class Person {

private String name;
private String sex;
private String race;
private int age;
private boolean alive;
private double height;
private ArrayList<String> hairColor;

public Person(
String name,
String sex,
String race,
int age,
double height,
ArrayList<String> hairColor,
boolean alive) {
this.name = name;
this.sex = sex;
this.race = race;
this.age = age;
this.height = height;
this.hairColor = hairColor;
this.alive = alive;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getRace() {
return race;
}

public void setRace(String race) {
this.race = race;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public double getHeight() {
return height;
}

public void setHeight(double height) {
this.height = height;
}

public ArrayList<String> getHairColor() throws PersonIsBaldException {
if (hairColor == null || hairColor.isEmpty()) {
this.hairColor = new ArrayList<>();
hairColor.add("Bald");
throw new PersonIsBaldException("No hair color? This person must be bald!");
}
return hairColor;
}

public void setHairColor(ArrayList<String> hairColor) {
this.hairColor = hairColor;
}

public ArrayList<String> getNaturalHairColor() {
ArrayList<String> naturalHairColor = new ArrayList<>();
ArrayList<String> possibleNaturalColor = new ArrayList<>();
possibleNaturalColor.add("Black");
possibleNaturalColor.add("Brown");
possibleNaturalColor.add("Blonde");
possibleNaturalColor.add("Ginger");
possibleNaturalColor.add("Auburn");
possibleNaturalColor.add("Albino");
possibleNaturalColor.add("Grey");

for (String color : hairColor) {
if (possibleNaturalColor.contains(color)) {
naturalHairColor.add(color);
break;
}
}
return naturalHairColor;
}

public String getLifeStatus() {
if (alive == true) {
return "Alive";
} else {
return "Deceased";
}
}

public void setLifeStatus(boolean alive) {
this.alive = alive;
}

public String getPersonInfo() {
return "Name: "
+ name
+ "| Gender Identity: "
+ sex
+ "| Race: "
+ race
+ "| Age: "
+ age
+ "| Height(In meters): "
+ height
+ "| Hair Color: "
+ hairColor
+ "| Status: "
+ getLifeStatus();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedifferently.lesson16.person;

class PersonIsBaldException extends Exception {
public PersonIsBaldException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package com.codedifferently.lesson16.person;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PersonTest {

Person person;

@BeforeEach
void setUp() {
ArrayList<String> hairColor = new ArrayList<>();
hairColor.add("Black");
hairColor.add("Purple");
person = new Person("Chigazo", "Male", "African-American", 20, 1.8288, hairColor, true);
}

@Test
public void testGetName() {
// Act
String actualName = person.getName();
// Arrange
String expectedName = "Chigazo";
// Assert
assertEquals(expectedName, actualName);
}

@Test
public void testSetName() {
// Arrange
String expectedSet = "Austin";
// Act
person.setName(expectedSet);
// Assert
assertEquals(expectedSet, person.getName());
}

@Test
public void testGetSex() {
// Act
String actualSex = person.getSex();
// Arrange
String expectedSex = "Male";
// Assert(Checking the value)
assertEquals(expectedSex, actualSex);
}

@Test
public void testSetSex() {
// Arrange
String expectedSex = "Female";
// Act
person.setSex(expectedSex);
// Assert
assertEquals(expectedSex, person.getSex());
}

@Test
public void testGetRace() {
// Act
String actualRace = person.getRace();
// Arrange
String expectedRace = "African-American";
// Assert(Checking the value)
assertEquals(expectedRace, actualRace);
}

@Test
public void testSetRace() {
// Arrange
String expectedRace = "Asian";
// Act
person.setRace(expectedRace);
// Assert
assertEquals(expectedRace, person.getRace());
}

@Test
public void testGetAge() {
// Act
int actualAge = person.getAge();
// Arrange
int expectedAge = 20;
// Assert(Checking the value)
assertEquals(expectedAge, actualAge);
}

@Test
public void testSetAge() {
// Arrange
int expectedAge = 21;
// Act
person.setAge(expectedAge);
// Assert
assertEquals(expectedAge, person.getAge());
}

@Test
public void testGetHeight() {
// Act
double actualHeight = person.getHeight();
// Arrange
double expectedHeight = 1.8288;
// Assert(Checking the value)
assertEquals(expectedHeight, actualHeight);
}

@Test
public void testSetHeight() {
// Arrange
double expectedHeight = 1.92024;
// Act
person.setHeight(expectedHeight);
// Assert
assertEquals(expectedHeight, person.getHeight());
}

@Test
public void testGetHairColor() throws PersonIsBaldException {
// Act
ArrayList<String> actualHairColor = person.getHairColor();
// Arrange
ArrayList<String> expectedHairColor = new ArrayList<>();
expectedHairColor.add("Black");
expectedHairColor.add("Purple");
// Assert
assertEquals(expectedHairColor, actualHairColor);
}

@Test
public void testGetHairColor__hairColorDoesNotExist() throws PersonIsBaldException {
// Arrange
Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true);
// Act
Exception exception =
Assertions.assertThrows(
PersonIsBaldException.class,
() -> {
baldPerson.getHairColor();
});
// Assert
assertEquals("No hair color? This person must be bald!", exception.getMessage());
}

@Test
public void testGetNaturalHairColor() {
ArrayList<String> expectedNaturalHairColor = new ArrayList<>();
expectedNaturalHairColor.add("Black");
ArrayList<String> actualNaturalHairColor = person.getNaturalHairColor();
assertEquals(expectedNaturalHairColor, actualNaturalHairColor);
}

@Test
public void testSetHairColor() throws PersonIsBaldException {
// Arrange
ArrayList<String> expectedHairColor = new ArrayList<>();
expectedHairColor.add("Brown");
// Act
person.setHairColor(expectedHairColor);
// Assert
assertEquals(expectedHairColor, person.getHairColor());
}

@Test
public void testGetLifeStatus() {
// Act
String actualLifeStatus = person.getLifeStatus();
// Arrange
String expectedHairColor = "Alive";
// Assert
assertEquals(expectedHairColor, actualLifeStatus);
}

@Test
public void testSetLifeStatus() {
// Arrange
boolean expectedLifeStatus = false;
// Act
person.setLifeStatus(expectedLifeStatus);
// Assert
assertEquals("Deceased", person.getLifeStatus());
}

@Test
public void testGetPersonInfo() {
String expectedPersonInfo =
"Name: Chigazo| Gender Identity: Male| Race: African-American| Age: 20| Height(In meters): 1.8288| Hair Color: [Black, Purple]| Status: Alive";

// Act
String actualPersonInfo = person.getPersonInfo();

// Assert
assertEquals(expectedPersonInfo, actualPersonInfo);
}
}