Skip to content

Commit 83a8793

Browse files
authored
Merge branch 'code-differently:main' into angielesson16
2 parents c16013a + 0f3904a commit 83a8793

File tree

12 files changed

+888
-0
lines changed

12 files changed

+888
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.lunch;
2+
3+
public class InvalidCalorieException extends Exception {
4+
public InvalidCalorieException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.codedifferently.lesson16.lunch;
2+
3+
import java.util.ArrayList;
4+
5+
public class Lunch {
6+
7+
public enum LunchType {
8+
VEGETARIAN,
9+
NON_VEGETARIAN,
10+
VEGAN,
11+
GLUTEN_FREE
12+
}
13+
14+
// Member variables
15+
private final String mainDish; // String type
16+
private final String sideDish; // String type
17+
private final int calories; // Integer type
18+
private final LunchType lunchType; // Enum type
19+
private final ArrayList<String> drinks; // Collection type (ArrayList)
20+
21+
// Constructor
22+
public Lunch(String mainDish, String sideDish, int calories, LunchType lunchType)
23+
throws InvalidCalorieException {
24+
if (calories <= 0) {
25+
throw new InvalidCalorieException("Calories cannot be zero or negative.");
26+
}
27+
this.mainDish = mainDish;
28+
this.sideDish = sideDish;
29+
this.calories = calories;
30+
this.lunchType = lunchType;
31+
this.drinks = new ArrayList<>();
32+
}
33+
34+
// Member function to add a drink
35+
public void addDrink(String drink) {
36+
drinks.add(drink);
37+
}
38+
39+
// Member function to get a healthy message based on calories
40+
public String getHealthMessage() {
41+
return (calories < 500) ? "This lunch is healthy!" : "This lunch is high in calories.";
42+
}
43+
44+
// Member function to display all drinks
45+
public void displayDrinks() {
46+
47+
System.out.println("Available drinks:");
48+
for (String drink : drinks) {
49+
System.out.println("- " + drink);
50+
}
51+
}
52+
53+
// Getters for member variables (optional)
54+
public String getMainDish() {
55+
return mainDish;
56+
}
57+
58+
public String getSideDish() {
59+
return sideDish;
60+
}
61+
62+
public int getCalories() {
63+
return calories;
64+
}
65+
66+
public LunchType getLunchType() {
67+
return lunchType;
68+
}
69+
70+
public ArrayList<String> getDrinks() {
71+
return drinks;
72+
}
73+
}
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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codedifferently.lesson16.studentinfo;
2+
3+
public enum Department {
4+
Sales,
5+
Finance,
6+
Technology,
7+
Research,
8+
Administration
9+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.codedifferently.lesson16.studentinfo;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
6+
public class Student {
7+
private long studentNumber;
8+
private String fullName;
9+
private Department department;
10+
private String emailAddress;
11+
private List<String> phoneNumbers;
12+
private LocalDate dateOfBirth;
13+
14+
public Student(
15+
long studentNumber,
16+
String fullName,
17+
Department department,
18+
String emailAddress,
19+
List<String> phoneNumbers,
20+
LocalDate dateOfBirth) {
21+
this.studentNumber = studentNumber;
22+
this.fullName = fullName;
23+
this.department = department;
24+
this.emailAddress = emailAddress;
25+
this.phoneNumbers = phoneNumbers;
26+
this.dateOfBirth = dateOfBirth;
27+
}
28+
29+
public long getStudentNumber() {
30+
return studentNumber;
31+
}
32+
33+
public void setStudentNumber(long studentNumber) {
34+
this.studentNumber = studentNumber;
35+
}
36+
37+
public String getFullName() {
38+
return fullName;
39+
}
40+
41+
public void setFullName(String fullName) {
42+
this.fullName = fullName;
43+
}
44+
45+
public Department getDepartment() {
46+
return department;
47+
}
48+
49+
public void setDepartment(Department department) {
50+
this.department = department;
51+
}
52+
53+
public String getEmailAddress() {
54+
return emailAddress;
55+
}
56+
57+
public void setEmailAddress(String emailAddress) {
58+
this.emailAddress = emailAddress;
59+
}
60+
61+
public List<String> getPhoneNumbers() {
62+
return phoneNumbers;
63+
}
64+
65+
public void setPhoneNumbers(List<String> phoneNumbers) {
66+
this.phoneNumbers = phoneNumbers;
67+
}
68+
69+
public LocalDate getDateOfBirth() {
70+
return dateOfBirth;
71+
}
72+
73+
public void setDateOfBirth(LocalDate dateOfBirth) {
74+
this.dateOfBirth = dateOfBirth;
75+
}
76+
77+
@Override
78+
public String toString() {
79+
return "Student{"
80+
+ "studentNumber="
81+
+ studentNumber
82+
+ ", fullName='"
83+
+ fullName
84+
+ '\''
85+
+ ", department="
86+
+ department
87+
+ ", emailAddress='"
88+
+ emailAddress
89+
+ '\''
90+
+ ", phoneNumbers="
91+
+ phoneNumbers
92+
+ ", dateOfBirth="
93+
+ dateOfBirth
94+
+ '}';
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.studentinfo;
2+
3+
public class StudentNotFoundException extends RuntimeException {
4+
public StudentNotFoundException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.codedifferently.lesson16.studentinfo;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class StudentService {
7+
8+
private final Map<Long, Student> students;
9+
10+
public StudentService() {
11+
students = new HashMap<>();
12+
}
13+
14+
private void checkIfStudentExist(long studentNumber) {
15+
if (students.containsKey(studentNumber)) {
16+
return;
17+
}
18+
throw new StudentNotFoundException("Student with number " + studentNumber + " not found");
19+
}
20+
21+
public void deleteStudent(long studentNumber) {
22+
checkIfStudentExist(studentNumber);
23+
students.remove(studentNumber);
24+
}
25+
26+
public void addStudent(Student student) {
27+
students.put(student.getStudentNumber(), student);
28+
}
29+
30+
public int countNumberOfTechDeptStudents() {
31+
int count = 0;
32+
for (Student student : students.values()) {
33+
if (student.getDepartment().equals(Department.Technology)) {
34+
count++;
35+
}
36+
}
37+
return count;
38+
}
39+
40+
public Student findStudentByStudentNumber(long studentNumber) {
41+
return students.get(studentNumber);
42+
}
43+
}

0 commit comments

Comments
 (0)