Skip to content

Commit d86f590

Browse files
committed
Add Java advanced project
1 parent fb4b0c4 commit d86f590

8 files changed

Lines changed: 200 additions & 11 deletions

File tree

CONCEPT_INDEX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Use this page to browse the same concept across every active language track.
6060
| --- | --- | --- | --- | --- | --- | --- |
6161
| 01-foundations | [C++](languages/cpp/projects/01-foundations/README.md) | [C#](languages/csharp/projects/01-foundations/README.md) | [Go](languages/go/projects/01-foundations/README.md) | [Java](languages/java/projects/01-foundations/README.md) | [Python](languages/python/projects/01-foundations/README.md) | [TypeScript](languages/typescript/projects/01-foundations/README.md) |
6262
| 02-core | [C++](languages/cpp/projects/02-core/README.md) | [C#](languages/csharp/projects/02-core/README.md) | [Go](languages/go/projects/02-core/README.md) | [Java](languages/java/projects/02-core/README.md) | [Python](languages/python/projects/02-core/README.md) | [TypeScript](languages/typescript/projects/02-core/README.md) |
63-
| 03-advanced | [C++](languages/cpp/projects/03-advanced/README.md) | [C#](languages/csharp/projects/03-advanced/README.md) | [Go](languages/go/projects/03-advanced/README.md) | Planned | [Python](languages/python/projects/03-advanced/README.md) | [TypeScript](languages/typescript/projects/03-advanced/README.md) |
63+
| 03-advanced | [C++](languages/cpp/projects/03-advanced/README.md) | [C#](languages/csharp/projects/03-advanced/README.md) | [Go](languages/go/projects/03-advanced/README.md) | [Java](languages/java/projects/03-advanced/README.md) | [Python](languages/python/projects/03-advanced/README.md) | [TypeScript](languages/typescript/projects/03-advanced/README.md) |
6464
| 04-expert | [C++](languages/cpp/projects/04-expert/README.md) | [C#](languages/csharp/projects/04-expert/README.md) | [Go](languages/go/projects/04-expert/README.md) | Planned | [Python](languages/python/projects/04-expert/README.md) | [TypeScript](languages/typescript/projects/04-expert/README.md) |
6565

6666
### Assessments

LANGUAGE_PARITY_MATRIX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Status labels:
8686
| --- | --- | --- | --- | --- | --- | --- |
8787
| 01-foundations | Done | Done | Done | Done | Done | Done |
8888
| 02-core | Done | Done | Done | Done | Done | Done |
89-
| 03-advanced | Done | Done | Done | Planned | Done | Done |
89+
| 03-advanced | Done | Done | Done | Done | Done | Done |
9090
| 04-expert | Done | Done | Done | Planned | Done | Done |
9191

9292
### Assessments

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ If you only want to learn one track, follow that track README first because lang
5656
| C++ | 00-setup, 01-foundations, 02-core, 03-advanced, 04-expert | Foundations, Core, Advanced, Expert, projects, assessments | Most complete and primary track |
5757
| C# | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
5858
| Go | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
59-
| Java | 01-foundations, 02-core, 03-advanced | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 2/4 projects, 2/4 assessments | Java 21 MVP through advanced modules; advanced checkpoints, expert, and later checkpoints planned |
59+
| Java | 01-foundations, 02-core, 03-advanced | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 3/4 projects, 2/4 assessments | Java 21 MVP through advanced modules and projects; advanced assessment, expert, and later checkpoints planned |
6060
| Python | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
6161
| TypeScript | 01-foundations, 02-core, 03-advanced, 04-expert | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 5/5 expert modules, 4/4 projects, 4/4 assessments | Module and checkpoint parity complete through expert |
6262

languages/java/CHECKLIST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
- [ ] projects/01-foundations
4040
- [ ] projects/02-core
41+
- [ ] projects/03-advanced
4142
- [ ] assessments/01-foundations
4243
- [ ] assessments/02-core
4344

@@ -57,7 +58,6 @@
5758
## Planned
5859

5960
- [ ] 04-expert modules
60-
- [ ] projects/03-advanced
6161
- [ ] projects/04-expert
6262
- [ ] assessments/03-advanced
6363
- [ ] assessments/04-expert

languages/java/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## Scope and Status
44

5-
This track currently covers `01-foundations`, `02-core`, and `03-advanced` as a Java 21 MVP, including projects and assessments for the first two implemented levels. Expert modules and later checkpoints are planned for future iterations.
5+
This track currently covers `01-foundations`, `02-core`, and `03-advanced` as a Java 21 MVP, including projects through `03-advanced` and assessments through `02-core`. Expert modules and later checkpoints are planned for future iterations.
66

77
- 8/8 foundations modules implemented.
88
- 6/6 core modules implemented.
99
- 5/5 advanced modules implemented (`structs-and-classes`, `constructors-and-invariants`, `copy-and-move-semantics`, `inheritance-and-polymorphism`, `templates-basics`).
1010
- 0/5 expert modules implemented.
11-
- 2/4 projects implemented (`01-foundations`, `02-core`).
11+
- 3/4 projects implemented (`01-foundations`, `02-core`, `03-advanced`).
1212
- 2/4 assessments implemented (`01-foundations`, `02-core`).
1313
- Uses Java 21 LTS with direct `javac` and `java` commands; no Maven or Gradle yet.
1414

@@ -58,6 +58,7 @@ java -cp build/java Main
5858
- Projects
5959
- [01-foundations](./projects/01-foundations/README.md)
6060
- [02-core](./projects/02-core/README.md)
61+
- [03-advanced](./projects/03-advanced/README.md)
6162
- Assessments
6263
- [01-foundations](./assessments/01-foundations/README.md)
6364
- [02-core](./assessments/02-core/README.md)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class Main {
5+
interface Reportable {
6+
String reportLine();
7+
}
8+
9+
record Student(String id, String name) {
10+
Student {
11+
if (id == null || id.isBlank()) {
12+
throw new IllegalArgumentException("id must not be blank");
13+
}
14+
if (name == null || name.isBlank()) {
15+
throw new IllegalArgumentException("name must not be blank");
16+
}
17+
}
18+
}
19+
20+
static final class Course implements Reportable {
21+
private final String title;
22+
private final int capacity;
23+
private final List<Student> enrolled = new ArrayList<>();
24+
25+
Course(String title, int capacity) {
26+
if (title == null || title.isBlank()) {
27+
throw new IllegalArgumentException("title must not be blank");
28+
}
29+
if (capacity < 0) {
30+
throw new IllegalArgumentException("capacity must not be negative");
31+
}
32+
this.title = title;
33+
this.capacity = capacity;
34+
}
35+
36+
boolean enroll(Student student) {
37+
if (enrolled.size() >= capacity || hasStudent(student.id())) {
38+
return false;
39+
}
40+
enrolled.add(student);
41+
return true;
42+
}
43+
44+
boolean dropById(String studentId) {
45+
return enrolled.removeIf(student -> student.id().equals(studentId));
46+
}
47+
48+
List<Student> rosterSnapshot() {
49+
return List.copyOf(enrolled);
50+
}
51+
52+
@Override
53+
public String reportLine() {
54+
return "Course: " + title + " | " + enrolled.size() + "/" + capacity + " enrolled";
55+
}
56+
57+
private boolean hasStudent(String studentId) {
58+
for (Student student : enrolled) {
59+
if (student.id().equals(studentId)) {
60+
return true;
61+
}
62+
}
63+
return false;
64+
}
65+
}
66+
67+
static final class Catalog<T extends Reportable> {
68+
private final List<T> items;
69+
70+
Catalog(List<T> items) {
71+
this.items = new ArrayList<>(items);
72+
}
73+
74+
List<T> snapshot() {
75+
return List.copyOf(items);
76+
}
77+
}
78+
79+
static <T extends Reportable> void printReport(String title, List<T> items) {
80+
System.out.println(title);
81+
for (T item : items) {
82+
System.out.println(item.reportLine());
83+
}
84+
}
85+
86+
public static void main(String[] args) {
87+
Student ana = new Student("S-101", "Ana Smith");
88+
Student bob = new Student("S-202", "Bob Lee");
89+
Student carla = new Student("S-303", "Carla Mendez");
90+
91+
Course javaAdvanced = new Course("JavaAdvanced", 2);
92+
Course algorithms = new Course("Algorithms", 3);
93+
94+
javaAdvanced.enroll(ana);
95+
javaAdvanced.enroll(bob);
96+
boolean overflowAccepted = javaAdvanced.enroll(carla);
97+
98+
algorithms.enroll(carla);
99+
algorithms.dropById("S-404");
100+
101+
List<Course> externalCourses = new ArrayList<>();
102+
externalCourses.add(javaAdvanced);
103+
externalCourses.add(algorithms);
104+
Catalog<Course> catalog = new Catalog<>(externalCourses);
105+
externalCourses.clear();
106+
107+
printReport("Course Enrollment Report", catalog.snapshot());
108+
System.out.println("Overflow accepted: " + overflowAccepted);
109+
System.out.println("Catalog courses after external clear: " + catalog.snapshot().size());
110+
System.out.println("JavaAdvanced roster snapshot: " + javaAdvanced.rosterSnapshot().size());
111+
}
112+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# 03 Advanced Capstone: Course Enrollment Manager
2+
3+
## Goal
4+
5+
Model courses and enrollments with Java classes, invariants, defensive copies, polymorphic reporting, and generic helpers.
6+
7+
## Learning Metadata
8+
9+
- Difficulty: Intermediate.
10+
- Estimated Time: 60-90 minutes.
11+
- Prerequisites: All `03-advanced` modules, especially `constructors-and-invariants`, `copy-and-move-semantics`, `inheritance-and-polymorphism`, and `templates-basics`.
12+
- Learning Focus: Integrate custom types, guarded state changes, copy boundaries, and reusable reporting in one small object-oriented program.
13+
14+
## Quick Run
15+
16+
```bash
17+
javac -d build/java languages/java/projects/03-advanced/Main.java
18+
java -cp build/java Main
19+
```
20+
21+
## Requirements
22+
23+
- Define a `Student` record with validated fields.
24+
- Define a `Course` class with title, capacity, enroll, drop, and status behavior.
25+
- Prevent enrollment beyond capacity and duplicate student IDs.
26+
- Return immutable snapshots instead of internal mutable lists.
27+
- Print multiple reportable objects through one generic helper.
28+
29+
## Concepts Practiced
30+
31+
- Records and classes.
32+
- Constructor-enforced invariants.
33+
- Defensive copies with `List.copyOf`.
34+
- Interfaces and polymorphic reporting.
35+
- Generic methods and generic containers.
36+
37+
## Sample Output
38+
39+
```text
40+
Course Enrollment Report
41+
Course: JavaAdvanced | 2/2 enrolled
42+
Course: Algorithms | 1/3 enrolled
43+
Overflow accepted: false
44+
Catalog courses after external clear: 2
45+
JavaAdvanced roster snapshot: 2
46+
```
47+
48+
## Cross-Language Notes
49+
50+
- Compared with C++, Java uses references and defensive copies instead of explicit move constructors.
51+
- Relative to Python, Java makes the model boundaries more verbose but more compile-time checked.
52+
- Compared with TypeScript, Java uses nominal interfaces and JVM collection APIs for snapshots.
53+
54+
## What To Check
55+
56+
- course capacity and duplicate student rules are enforced
57+
- external list changes do not mutate the catalog
58+
- report output reflects the final object state
59+
- generic reporting works for more than one concrete object
60+
61+
## Extension Ideas
62+
63+
- Add waitlist behavior.
64+
- Read enrollment commands from a file.
65+
- Add grade summaries per course.

scripts/automation_manifest.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
]
139139
},
140140
"checkpoints": {
141-
"projects": ["01-foundations", "02-core"],
141+
"projects": ["01-foundations", "02-core", "03-advanced"],
142142
"assessments": ["01-foundations", "02-core"]
143143
},
144144
"checkpoint_main": "Main.java",
@@ -149,15 +149,15 @@
149149
},
150150
"track_readme": "languages/java/README.md",
151151
"track_readme_markers": [
152-
"This track currently covers `01-foundations`, `02-core`, and `03-advanced` as a Java 21 MVP, including projects and assessments for the first two implemented levels. Expert modules and later checkpoints are planned for future iterations.",
152+
"This track currently covers `01-foundations`, `02-core`, and `03-advanced` as a Java 21 MVP, including projects through `03-advanced` and assessments through `02-core`. Expert modules and later checkpoints are planned for future iterations.",
153153
"- 8/8 foundations modules implemented.",
154154
"- 6/6 core modules implemented.",
155155
"- 5/5 advanced modules implemented (`structs-and-classes`, `constructors-and-invariants`, `copy-and-move-semantics`, `inheritance-and-polymorphism`, `templates-basics`).",
156-
"- 2/4 projects implemented (`01-foundations`, `02-core`).",
156+
"- 3/4 projects implemented (`01-foundations`, `02-core`, `03-advanced`).",
157157
"- 2/4 assessments implemented (`01-foundations`, `02-core`).",
158158
"- Uses Java 21 LTS with direct `javac` and `java` commands; no Maven or Gradle yet."
159159
],
160-
"root_status_row": "| Java | 01-foundations, 02-core, 03-advanced | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 2/4 projects, 2/4 assessments | Java 21 MVP through advanced modules; advanced checkpoints, expert, and later checkpoints planned |"
160+
"root_status_row": "| Java | 01-foundations, 02-core, 03-advanced | 8/8 foundations modules, 6/6 core modules, 5/5 advanced modules, 3/4 projects, 2/4 assessments | Java 21 MVP through advanced modules and projects; advanced assessment, expert, and later checkpoints planned |"
161161
},
162162
"python": {
163163
"extension": "py",
@@ -227,7 +227,7 @@
227227
"| types-and-io | Done | Done | Done | Done | Done | Done |",
228228
"| 02-core | Done | Done | Done | Done | Done | Done |",
229229
"| 1 | input-validation | Done | Done | Done | Done | Done | Done |",
230-
"| 03-advanced | Done | Done | Done | Planned | Done | Done |",
230+
"| 03-advanced | Done | Done | Done | Done | Done | Done |",
231231
"| 04-expert | Done | Done | Done | Planned | Done | Done |"
232232
]
233233
}
@@ -915,6 +915,17 @@
915915
}
916916
],
917917
"cleanup_paths": ["core_assessment_report.txt"]
918+
},
919+
{
920+
"program": "languages/java/projects/03-advanced/Main.java",
921+
"required_stdout_contains": [
922+
"Course Enrollment Report",
923+
"Course: JavaAdvanced | 2/2 enrolled",
924+
"Course: Algorithms | 1/3 enrolled",
925+
"Overflow accepted: false",
926+
"Catalog courses after external clear: 2",
927+
"JavaAdvanced roster snapshot: 2"
928+
]
918929
}
919930
]
920931
}

0 commit comments

Comments
 (0)