Skip to content

Commit a2ce1af

Browse files
authored
Merge branch 'code-differently:main' into Lesson_15
2 parents 0c3eb22 + f395439 commit a2ce1af

File tree

24 files changed

+1506
-0
lines changed

24 files changed

+1506
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.footballteamobject;
2+
3+
public class DuplicatePlayerException extends Exception {
4+
public DuplicatePlayerException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.codedifferently.footballteamobject;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class FootballTeam {
7+
8+
public static class DuplicatePlayerException extends Exception {
9+
public DuplicatePlayerException(String message) {
10+
super(message);
11+
}
12+
}
13+
14+
private int playerCount;
15+
private int jerseyNumber50AndOver;
16+
private int jerseyNumberUnder50;
17+
private Map<Integer, String> players = new HashMap<>();
18+
private final String teamName;
19+
private final String location;
20+
private final Conference conference;
21+
22+
public FootballTeam(
23+
String teamName, String location, Conference conference, Map<Integer, String> players) {
24+
this.teamName = teamName;
25+
this.location = location;
26+
this.conference = conference;
27+
this.players = players;
28+
}
29+
30+
public enum Conference {
31+
// Power Five Conferences
32+
ACC,
33+
BIG_12,
34+
BIG_10,
35+
PAC_12,
36+
SEC,
37+
// Group of Five Conferences
38+
AMERICAN,
39+
CONFERENCE_USA,
40+
MAC,
41+
MOUNTAIN_WEST,
42+
SUN_BELT
43+
}
44+
45+
public boolean isPowerFive() {
46+
if (conference == Conference.ACC
47+
|| conference == Conference.BIG_12
48+
|| conference == Conference.BIG_10
49+
|| conference == Conference.PAC_12
50+
|| conference == Conference.SEC) {
51+
return true;
52+
}
53+
return false;
54+
}
55+
56+
public String getTeamName() {
57+
return teamName;
58+
}
59+
60+
public String getLocation() {
61+
return location;
62+
}
63+
64+
public Conference getConference() {
65+
return conference;
66+
}
67+
68+
public int getPlayerCount() {
69+
return playerCount;
70+
}
71+
72+
public Map<Integer, String> getPlayers() {
73+
return players;
74+
}
75+
76+
public void addPlayer(int number, String name) throws DuplicatePlayerException {
77+
if (players.containsKey(number)) {
78+
throw new DuplicatePlayerException("A player with that number already exists.");
79+
}
80+
players.put(number, name);
81+
playerCount++;
82+
}
83+
84+
public void removePlayer(int number) {
85+
players.remove(number);
86+
playerCount--;
87+
}
88+
89+
public void tallyJerseyNumbers() {
90+
for (Map.Entry<Integer, String> entry : players.entrySet()) {
91+
if (entry.getKey() < 50) {
92+
jerseyNumberUnder50++;
93+
} else {
94+
jerseyNumber50AndOver++;
95+
}
96+
}
97+
}
98+
99+
public int getJerseyNumber50AndOver() {
100+
return jerseyNumber50AndOver;
101+
}
102+
103+
public int getJerseyNumberUnder50() {
104+
return jerseyNumberUnder50;
105+
}
106+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.amiyahjones;
2+
3+
public class ClassroomFullException extends Exception {
4+
public ClassroomFullException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.codedifferently.lesson16.amiyahjones;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class JobReadinessProgram {
7+
private final boolean isSuccessful;
8+
ArrayList<String> students;
9+
private final Level readinessLevel;
10+
private final int lecturePerWeek;
11+
private static final ArrayList<String> teacherAssistants = new ArrayList<>();
12+
private String assignedTA;
13+
private final String mentor;
14+
private final String socialSupport;
15+
private final int MAX_CAPACITY = 22;
16+
17+
static {
18+
teacherAssistants.add("Rich");
19+
teacherAssistants.add("Vicente");
20+
teacherAssistants.add("Jordan");
21+
}
22+
23+
enum Level {
24+
Beginner,
25+
Intermediate,
26+
Advanced
27+
}
28+
29+
public JobReadinessProgram(Level readinessLevel, boolean isSuccessful, String assignedTA) {
30+
students = new ArrayList<>();
31+
this.readinessLevel = readinessLevel;
32+
this.isSuccessful = isSuccessful;
33+
lecturePerWeek = 3;
34+
mentor = "Anthony";
35+
socialSupport = "Estelle";
36+
if (teacherAssistants.contains(assignedTA)) {
37+
this.assignedTA = assignedTA;
38+
}
39+
}
40+
41+
public void addStudent(String studentName) throws ClassroomFullException {
42+
int classroomCheck = students.size();
43+
if (classroomCheck == MAX_CAPACITY) {
44+
throw new ClassroomFullException("Classroom is full");
45+
}
46+
students.add(studentName);
47+
}
48+
49+
public int getStudentCount() {
50+
int count = students.size();
51+
System.out.println("Total students enrolled: " + count);
52+
return count;
53+
}
54+
55+
public void displayStudents() {
56+
for (String student : students) {
57+
System.out.println(student);
58+
}
59+
}
60+
61+
public String checkReadiness() {
62+
return (readinessLevel == Level.Beginner)
63+
? "Needs more training."
64+
: "Ready for job applications!";
65+
}
66+
67+
public int getLecturesPerWeek() {
68+
System.out.println("Number of lectures students have: ");
69+
return lecturePerWeek;
70+
}
71+
72+
public String getMentor() {
73+
return mentor;
74+
}
75+
76+
public String getSocialSupport() {
77+
return socialSupport;
78+
}
79+
80+
public List<String> getTeacherAssistants() {
81+
return new ArrayList<>(teacherAssistants);
82+
}
83+
84+
public boolean assignTA(String taName) {
85+
if (teacherAssistants.contains(taName)) {
86+
this.assignedTA = taName;
87+
return true;
88+
} else {
89+
throw new IllegalArgumentException("Not a TA. Please choose from: " + getTeacherAssistants());
90+
}
91+
}
92+
93+
public void displayAssignedTA() {
94+
if (assignedTA != null) {
95+
System.out.println("Assigned Teacher Assistant: " + assignedTA);
96+
} else {
97+
System.out.println("No Teacher Assistant assigned.");
98+
}
99+
}
100+
101+
public Boolean verifyIsSuccessful() {
102+
if (isSuccessful) {
103+
System.out.println("Congraulations! You made it through your journey!");
104+
} else {
105+
System.out.println("At least you got to know what software engineering is like!");
106+
}
107+
return isSuccessful;
108+
}
109+
}

0 commit comments

Comments
 (0)