Skip to content

Commit 0f3904a

Browse files
AmiyahJoAmiyahJo
andauthored
Feat: add Amiyah Jones' custom class, exception, and objects - Lesson 16 (#518)
* Create README.md Accidentally removed my work the 1st time by merging * Delete lesson_00/amiyahjones/README.md * feat: adds java class fix: changed class name from codeTraining to cjobReadinessLab * rm: old classname * chore: pascal case * feat: adds 5 variables int , string , arrayList as the three different types * feat: adds boolean isSuccessful tracks progress later on for my class * fix: Pascal case JobReadinessLab * feat: adds students * chore: remove comments * feat: adds package * feat: adds enum type , jobreadinesslab constructor * feat: adds 'this' to disambiguate my variables * chore: move strings in one line * feat: adds two member functions * chore: remove 'private' status fom the empty students list * feat: adds more member variables fix: illegal start expression in checkReadiness , and boolean verifyIsSuccessful feat: adds final to variables * fix: changed member function getStudentCount to countStudents * chore: whitespace edit * chore: whitespace adjustment * feat: adds custom exception * feat: adds tests * chore: comment out class objects working on creating a test first * rm: JobReadinessLab class file * fix: rename test to JobReadinessProgram * chore: whitespace feat: adds action to testAddStudent() * rm: student exception feat: adds testAddStudent more simple. * feat: adds tests and corresponding variables in my class * fix: parameters adjusted feat: adds import to JobReadinessProgram class * feat: adds isSuccessful method * feat: adds lecturePerWeek tests and variable * feat: adds getMentor and getSocialSupport * fix: chaged assigned ta from hashmap back to an array list feat: adds ta names , and an illlegal exception for invalid ta * feat: adds displayStudents * feat: adds custom exception * fix: apply throw exception to addStudent tests * feat: initialized MAX_CAPACITY , adds an if statement for conditional statement fix: changed order of logic in addStudent() * feat: adds tests if claassroom is full , assign TA test , display TA. minor details changed as well (parameter , TA) * fix: organization moved isSuccessful at the bottom * fix: tests from failure to success * fix: spotless apply * fix: changes method in jobReadinessprogram to getLecturesPerWeek() chore: changed null values in the constructor * chore: spotless apply in JobReadinessProgram --------- Co-authored-by: AmiyahJo <[email protected]>
1 parent 21f47d5 commit 0f3904a

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.codedifferently.lesson16.amiyahjones;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.codedifferently.lesson16.amiyahjones.JobReadinessProgram.Level;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class JobReadinessProgramTest {
9+
10+
@Test
11+
void testAddStudent() throws ClassroomFullException {
12+
// Arrange
13+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, false, "rich");
14+
15+
// Act
16+
program.addStudent("John");
17+
18+
// Assert
19+
assertEquals(program.getStudentCount(), 1);
20+
}
21+
22+
@Test
23+
void testGetStudentCount() throws ClassroomFullException {
24+
// Arrange
25+
JobReadinessProgram program = new JobReadinessProgram(Level.Advanced, true, "vicente");
26+
program.addStudent("John");
27+
28+
// Act
29+
int actualCount = program.getStudentCount();
30+
31+
// Assert
32+
int expectedCount = 1;
33+
assertEquals(expectedCount, actualCount);
34+
}
35+
36+
@Test
37+
void testClassroomFullException() {
38+
// Arrange
39+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, true, "Jordan");
40+
41+
// Act
42+
try {
43+
for (int i = 1; i <= 23; i++) {
44+
program.addStudent("Student " + i);
45+
}
46+
} catch (ClassroomFullException e) {
47+
System.out.println(e.getMessage());
48+
}
49+
50+
// Assert
51+
int currentCount = program.getStudentCount();
52+
assert (currentCount == 22);
53+
}
54+
55+
@Test
56+
void testCheckReadinessBeginner() {
57+
JobReadinessProgram student = new JobReadinessProgram(Level.Beginner, true, null);
58+
String result = student.checkReadiness();
59+
assertEquals("Needs more training.", result);
60+
}
61+
62+
@Test
63+
void testCheckReadinessIntermediate() {
64+
JobReadinessProgram student = new JobReadinessProgram(Level.Intermediate, true, null);
65+
String result = student.checkReadiness();
66+
assertEquals("Ready for job applications!", result);
67+
}
68+
69+
@Test
70+
void testCheckReadinessAdvanced() {
71+
JobReadinessProgram student = new JobReadinessProgram(Level.Advanced, true, "vicente");
72+
String result = student.checkReadiness();
73+
assertEquals("Ready for job applications!", result);
74+
}
75+
76+
@Test
77+
void testVerifyIfSuccessful() {
78+
JobReadinessProgram graduate = new JobReadinessProgram(Level.Intermediate, true, "rich");
79+
80+
var graduation = graduate.verifyIsSuccessful();
81+
assertEquals(true, graduation);
82+
}
83+
84+
@Test
85+
void testLecturePerWeek() {
86+
JobReadinessProgram program = new JobReadinessProgram(Level.Advanced, true, "rich");
87+
var lecturesAttended = program.getLecturesPerWeek();
88+
assertEquals(3, lecturesAttended);
89+
}
90+
91+
@Test
92+
void testGetMentor() {
93+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, true, "jordan");
94+
var AssignedMentor = program.getMentor();
95+
assertEquals("Anthony", AssignedMentor);
96+
}
97+
98+
@Test
99+
void testGetSocialSupport() {
100+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, true, "vicente");
101+
var SocialSupport = program.getSocialSupport();
102+
assertEquals("Estelle", SocialSupport);
103+
}
104+
105+
@Test
106+
void testGetTeacherAssistants() {
107+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, true, "vicente");
108+
var teacherAssitant = program.getTeacherAssistants();
109+
assertEquals(program.getTeacherAssistants(), teacherAssitant);
110+
}
111+
112+
@Test
113+
void testAssignTA() {
114+
JobReadinessProgram program = new JobReadinessProgram(Level.Beginner, true, "Jordan");
115+
boolean result = program.assignTA("Vicente");
116+
assert (result == true);
117+
118+
try {
119+
program.assignTA("Invalid TA");
120+
} catch (IllegalArgumentException e) {
121+
System.out.println(e.getMessage());
122+
}
123+
}
124+
125+
@Test
126+
void testDisplayAssignedTA() {
127+
JobReadinessProgram program = new JobReadinessProgram(Level.Advanced, true, "rich");
128+
program.displayAssignedTA();
129+
130+
JobReadinessProgram emptyProgram = new JobReadinessProgram(Level.Beginner, true, "Invalid TA");
131+
emptyProgram.displayAssignedTA();
132+
}
133+
}

0 commit comments

Comments
 (0)