Skip to content

Commit edfcb3b

Browse files
authored
Merge branch 'code-differently:main' into angielesson16
2 parents 83a8793 + 448b52e commit edfcb3b

File tree

18 files changed

+1046
-0
lines changed

18 files changed

+1046
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.codedifferently.lesson16.person;
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+
public Person(
16+
String name,
17+
String sex,
18+
String race,
19+
int age,
20+
double height,
21+
ArrayList<String> hairColor,
22+
boolean alive) {
23+
this.name = name;
24+
this.sex = sex;
25+
this.race = race;
26+
this.age = age;
27+
this.height = height;
28+
this.hairColor = hairColor;
29+
this.alive = alive;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public String getSex() {
41+
return sex;
42+
}
43+
44+
public void setSex(String sex) {
45+
this.sex = sex;
46+
}
47+
48+
public String getRace() {
49+
return race;
50+
}
51+
52+
public void setRace(String race) {
53+
this.race = race;
54+
}
55+
56+
public int getAge() {
57+
return age;
58+
}
59+
60+
public void setAge(int age) {
61+
this.age = age;
62+
}
63+
64+
public double getHeight() {
65+
return height;
66+
}
67+
68+
public void setHeight(double height) {
69+
this.height = height;
70+
}
71+
72+
public ArrayList<String> getHairColor() throws PersonIsBaldException {
73+
if (hairColor == null || hairColor.isEmpty()) {
74+
this.hairColor = new ArrayList<>();
75+
hairColor.add("Bald");
76+
throw new PersonIsBaldException("No hair color? This person must be bald!");
77+
}
78+
return hairColor;
79+
}
80+
81+
public void setHairColor(ArrayList<String> hairColor) {
82+
this.hairColor = hairColor;
83+
}
84+
85+
public ArrayList<String> getNaturalHairColor() {
86+
ArrayList<String> naturalHairColor = new ArrayList<>();
87+
ArrayList<String> possibleNaturalColor = new ArrayList<>();
88+
possibleNaturalColor.add("Black");
89+
possibleNaturalColor.add("Brown");
90+
possibleNaturalColor.add("Blonde");
91+
possibleNaturalColor.add("Ginger");
92+
possibleNaturalColor.add("Auburn");
93+
possibleNaturalColor.add("Albino");
94+
possibleNaturalColor.add("Grey");
95+
96+
for (String color : hairColor) {
97+
if (possibleNaturalColor.contains(color)) {
98+
naturalHairColor.add(color);
99+
break;
100+
}
101+
}
102+
return naturalHairColor;
103+
}
104+
105+
public String getLifeStatus() {
106+
if (alive == true) {
107+
return "Alive";
108+
} else {
109+
return "Deceased";
110+
}
111+
}
112+
113+
public void setLifeStatus(boolean alive) {
114+
this.alive = alive;
115+
}
116+
117+
public String getPersonInfo() {
118+
return "Name: "
119+
+ name
120+
+ "| Gender Identity: "
121+
+ sex
122+
+ "| Race: "
123+
+ race
124+
+ "| Age: "
125+
+ age
126+
+ "| Height(In meters): "
127+
+ height
128+
+ "| Hair Color: "
129+
+ hairColor
130+
+ "| Status: "
131+
+ getLifeStatus();
132+
}
133+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.person;
2+
3+
class PersonIsBaldException extends Exception {
4+
public PersonIsBaldException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.codedifferently.lesson16.coins;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Coins {
7+
8+
public enum CoinType {
9+
PENNY,
10+
NICKEL,
11+
DIME,
12+
QUARTER
13+
}
14+
15+
private final CoinType coinType;
16+
private final int coinValue;
17+
private final boolean coinIsRare;
18+
private final double coinGramWeight;
19+
private final int coinAge;
20+
private final List<String> material;
21+
private static final List<Coins> coinCollection = new ArrayList<>();
22+
23+
// constructor
24+
public Coins(
25+
CoinType coinType,
26+
int coinValue,
27+
Boolean coinIsRare,
28+
Double coinGramWeight,
29+
int coinAge,
30+
List<String> material) {
31+
this.coinType = coinType;
32+
this.coinValue = coinValue;
33+
this.coinIsRare = coinIsRare;
34+
this.coinGramWeight = coinGramWeight;
35+
this.coinAge = coinAge;
36+
this.material = material;
37+
}
38+
39+
// Getters and Setters
40+
public CoinType getCoinType() {
41+
return coinType;
42+
}
43+
44+
public int getCoinValue() {
45+
return coinValue;
46+
}
47+
48+
public boolean isCoinRare() {
49+
return coinIsRare;
50+
}
51+
52+
public double getCoinGramWeight() {
53+
return coinGramWeight;
54+
}
55+
56+
public int getCoinAge() {
57+
return coinAge;
58+
}
59+
60+
public List<String> getMaterial() {
61+
List<String> materialsList = new ArrayList<>();
62+
for (String mat : material) {
63+
materialsList.add(mat);
64+
}
65+
return materialsList;
66+
}
67+
68+
public static int convertNickelsToDimes(int totalNickels) {
69+
if (totalNickels < 1) {
70+
throw new IllegalArgumentException("you do not have enough nickles");
71+
}
72+
return totalNickels / 2;
73+
}
74+
75+
public static List<Coins> setCoinCollection() {
76+
Coins penny = new Coins(Coins.CoinType.PENNY, 1, true, 2.5, 1977, List.of("zinc", "copper"));
77+
Coins nickel =
78+
new Coins(Coins.CoinType.NICKEL, 5, true, 5.0, 1953, List.of("nickel", "copper"));
79+
Coins dime = new Coins(CoinType.DIME, 10, true, 10.0, 1957, List.of("nickel", "copper"));
80+
81+
coinCollection.add(penny);
82+
coinCollection.add(nickel);
83+
coinCollection.add(dime);
84+
return coinCollection;
85+
}
86+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.codedifferently.lesson16.hummadtanweer;
2+
3+
import java.util.ArrayList;
4+
5+
public class Person {
6+
private final String name;
7+
private final int age;
8+
private final Gender gender;
9+
private final ArrayList<String> hobbies;
10+
private final String email;
11+
private final int MAX_HOBBIES = 2;
12+
13+
public class HobbyLimitExceededException extends Exception {
14+
public HobbyLimitExceededException(String message) {
15+
super(message);
16+
}
17+
}
18+
19+
enum Gender {
20+
MALE,
21+
FEMALE,
22+
OTHER
23+
}
24+
25+
public Person(String name, int age, Gender gender, String email) {
26+
this.name = name;
27+
this.age = age;
28+
this.gender = gender;
29+
this.email = email;
30+
this.hobbies = new ArrayList<>();
31+
}
32+
33+
public void addHobby(String hobby) throws HobbyLimitExceededException {
34+
if (hobbies.size() >= MAX_HOBBIES) {
35+
throw new HobbyLimitExceededException("Cannot add more than " + MAX_HOBBIES + " hobbies.");
36+
}
37+
hobbies.add(hobby);
38+
}
39+
40+
public ArrayList<String> getHobbies() {
41+
return hobbies;
42+
}
43+
44+
public boolean isAdult() {
45+
return age >= 18;
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public String getEmail() {
53+
return email;
54+
}
55+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.shawndunsmore;
2+
3+
public enum BuyType {
4+
BONUS_BUY,
5+
DOUBLE_CHANCE,
6+
NORMAL_BUY,
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codedifferently.lesson16.shawndunsmore;
2+
3+
public class InvalidPayAmountException extends Exception {
4+
5+
public InvalidPayAmountException(String message) {
6+
super(message);
7+
}
8+
}

0 commit comments

Comments
 (0)