|
| 1 | +package com.codedifferently.lesson16; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | + |
| 5 | +public class Person { |
| 6 | + |
| 7 | + private String name; |
| 8 | + private String sex; |
| 9 | + private String race; |
| 10 | + private int age; |
| 11 | + private boolean alive; |
| 12 | + private double height; |
| 13 | + private ArrayList<String> hairColor; |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + public Person(String name, String sex, String race, int age, double height, ArrayList hairColor, boolean alive){ |
| 18 | + this.name = name; |
| 19 | + this.sex = sex; |
| 20 | + this.race = race; |
| 21 | + this.age = age; |
| 22 | + this.height = height; |
| 23 | + this.hairColor = hairColor; |
| 24 | + this.alive = alive; |
| 25 | + } |
| 26 | + |
| 27 | + public String getName() { |
| 28 | + return name; |
| 29 | + } |
| 30 | + |
| 31 | + public void setName(String name) { |
| 32 | + this.name = name; |
| 33 | + } |
| 34 | + |
| 35 | + public String getSex() { |
| 36 | + return sex; |
| 37 | + } |
| 38 | + |
| 39 | + public void setSex(String sex) { |
| 40 | + this.sex = sex; |
| 41 | + } |
| 42 | + |
| 43 | + public String getRace() { |
| 44 | + return race; |
| 45 | + } |
| 46 | + |
| 47 | + public void setRace(String race) { |
| 48 | + this.race = race; |
| 49 | + } |
| 50 | + |
| 51 | + public int getAge() { |
| 52 | + return age; |
| 53 | + } |
| 54 | + |
| 55 | + public void setAge(int age) { |
| 56 | + this.age = age; |
| 57 | + } |
| 58 | + |
| 59 | + public double getHeight() { |
| 60 | + return height; |
| 61 | + } |
| 62 | + |
| 63 | + public void setHeight(double height) { |
| 64 | + this.height = height; |
| 65 | + } |
| 66 | + |
| 67 | + public ArrayList<String> getHairColor() { |
| 68 | + if (hairColor == null) { |
| 69 | + throw new IllegalArgumentException("No hair color? This person must be bald!"); |
| 70 | + } |
| 71 | + return hairColor; |
| 72 | + } |
| 73 | + |
| 74 | + public void setHairColor(ArrayList hairColor) { |
| 75 | + this.hairColor = hairColor; |
| 76 | + } |
| 77 | + |
| 78 | + public ArrayList<String> getNaturalHairColor() { |
| 79 | + ArrayList<String> naturalHairColor = new ArrayList<>(); |
| 80 | + ArrayList<String> possibleNaturalColor = new ArrayList<>(); |
| 81 | + possibleNaturalColor.add("Black"); |
| 82 | + possibleNaturalColor.add("Brown"); |
| 83 | + possibleNaturalColor.add("Blonde"); |
| 84 | + possibleNaturalColor.add("Ginger"); |
| 85 | + possibleNaturalColor.add("Auburn"); |
| 86 | + possibleNaturalColor.add("Albino"); |
| 87 | + possibleNaturalColor.add("Grey"); |
| 88 | + |
| 89 | + for (String color : hairColor) { |
| 90 | + if (possibleNaturalColor.contains(color)) { |
| 91 | + naturalHairColor.add(color); |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + return naturalHairColor; |
| 96 | + } |
| 97 | + |
| 98 | + public String getLifeStatus() { |
| 99 | + if (alive == true) { |
| 100 | + return "alive"; |
| 101 | + } else { |
| 102 | + return "deceased"; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + public void setLifeStatus(boolean alive) { |
| 107 | + this.alive = alive; |
| 108 | + } |
| 109 | + |
| 110 | + public String getPersonInfo() { |
| 111 | + return "Name: " + name + |
| 112 | + "Gender Identity: " + sex + |
| 113 | + "Race: " + race + |
| 114 | + "Age: " + age + |
| 115 | + "Height(In meters): " + height + |
| 116 | + "Hair Color: " + hairColor + |
| 117 | + "Status: " + getLifeStatus(); |
| 118 | + } |
| 119 | +} |
0 commit comments