{"id":24021178,"url":"https://github.com/zipcodecore/maven.learnerlab","last_synced_at":"2025-06-25T18:35:17.828Z","repository":{"id":43909313,"uuid":"97118616","full_name":"ZipCodeCore/Maven.LearnerLab","owner":"ZipCodeCore","description":"Week 4 Project: Instructor, Student, Classroom","archived":false,"fork":false,"pushed_at":"2021-09-14T02:52:04.000Z","size":42,"stargazers_count":2,"open_issues_count":57,"forks_count":86,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-15T21:39:32.331Z","etag":null,"topics":["corejava","corejava-chapter5"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZipCodeCore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-13T12:08:52.000Z","updated_at":"2023-09-27T04:11:22.000Z","dependencies_parsed_at":"2022-09-17T07:10:21.695Z","dependency_job_id":null,"html_url":"https://github.com/ZipCodeCore/Maven.LearnerLab","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/ZipCodeCore/Maven.LearnerLab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FMaven.LearnerLab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FMaven.LearnerLab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FMaven.LearnerLab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FMaven.LearnerLab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZipCodeCore","download_url":"https://codeload.github.com/ZipCodeCore/Maven.LearnerLab/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FMaven.LearnerLab/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261931463,"owners_count":23232089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["corejava","corejava-chapter5"],"created_at":"2025-01-08T12:39:43.519Z","updated_at":"2025-06-25T18:35:17.799Z","avatar_url":"https://github.com/ZipCodeCore.png","language":"Java","readme":"# Leon's Lengthy Learner Lab \n* **Objective** - to implement a `ZipCodeWilmington` class which _mediates_ a _composite_ `Students` and `Instructors` _singleton_ reference.\n* **Purpose** - to demonstrate the use of\n\t* [interfaces](https://stackoverflow.com/questions/1321122/what-is-an-interface-in-java)\n\t* [abstract classes](https://stackoverflow.com/questions/1320745/abstract-class-in-java)\n\t* [concrete classes](https://stackoverflow.com/questions/43224901/what-is-the-concrete-class-in-java)\n\t* [enums](https://stackoverflow.com/questions/4709175/what-are-enums-and-why-are-they-useful)\n\t* [generics](https://stackoverflow.com/questions/7815528/what-are-generics-in-java/7815579)\n\n\n### Part 1.1 - Create `Person` Class\n* Create a `Person` class.\n\t* The class should declare a `final` field named `id` of type `long`.\n\t* The class should declare a field named `name` of type `String`.\t\n\t* `Person` constructor should have a parameter of type `long` and `String` which sets the `id` and `name` field to the respective values.\n\t* The class should define a `getId()` method which returns the `Person` object's `id` field.\n\t* The class should define a `getName()` method which returns the `Person` object's `name` field.\n\t* The class should define a `setName()` method which sets the `Person` object's `name` field.\n\n-\n### Part 1.0 - Test `Person`\n* Create a `TestPerson` class.\n\t* Create a `testConstructor` method which ensures that a `Person` object's `id` and `name` field are being set upon construction.\n\t* Create a `testSetName` method which ensures that a `Person` object's `name` variable is being set by invoking the `.setName` method.\n\n-\n### Part 2.0 - Create `Learner` Interface\n* Create a `Learner` interface.\n\t* `Learner` should declare method signature:\n\t\t* Method name: `learn`\n\t\t* Method parameters: `double numberOfHours`\n\t\t* Method return-type: `void`\n\t* `Learner` should declare method signature:\n\t\t* Method name: `getTotalStudyTime`\n\t\t* Method return-type: `Double`\n\n-\n### Part 3.1 - Create `Student` Class\n* Create a `Student` class such that:\n\t* `Student` is a subclass of `Person`\n\t* `Student` implements the `Learner` interface\n\t* `Student` should have an instance variable `totalStudyTime` of type `double`\n\t* `Student` should have a concrete implementation of the `learn` method which increments the `totalStudyTime` variable by the specified `numberOfHours` argument.\n\t* `Student` should have a `getTotalStudyTime()` method which returns the `totalStudyTime` instance variable.\n\n\n-\n### Part 3.0 - Test `Student`\n* Create a `TestStudent` class.\n\t* Create a `testImplementation` method that asserts that a `Student` is an `instanceof` a `Learner`.\n\t* Create a `testInheritance` method that asserts that a `Student` is an `instanceof` a `Person`.\n\t* Create a `testLearn` method that ensures a `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` by invoking the `.learn` method.\n\n-\n### Part 4.0 - Create `Teacher` Interface\n* Create a `Teacher` interface.\n\t* `Teacher` should declare a `teach` method signature:\n\t\t* Method name: `teach`\n\t\t* Method parameters:\n\t\t\t* `Learner learner`\n\t\t\t* `double numberOfHours`\n\t\t* Method return-type: `void` \n\n\t* `Teacher` should declare a `lecture` method signature:\n\t\t* Method name: `lecture`\n\t\t* Method parameters:\n\t\t\t* `Learner[] learners`\n\t\t\t* `double numberOfHours`\n\t\t* Method return-type: `void`\n\n\t\t\n-\n### Part 5.1 - Create `Instructor` Class\n* Create an `Instructor` class such that:\n\t* `Instructor` is a subclass of `Person`\n\t* `Instructor` implements the `Teacher` interface\n\t* `Instructor` should have a concrete implementation of the `teach` method which invokes the `learn` method on the specified `Learner` object.\n\t* `Instructor` should have a concrete implementation of the `lecture` method which invokes the `learn` method on each of the elements in the specified array of `Learner` objects.\n\t\t* `numberOfHours` should be evenly split amongst the learners.\n\t\t\t* `double numberOfHoursPerLearner = numberOfHours / learners.length;`\n\n-\n### Part 5.0 - Test `Instructor`\n* Create a `TestInstructor` class.\n\t* Create a `testImplementation` method that asserts that an `Instructor` is an `instanceof` a `Teacher`.\n\t* Create a `testInheritance` method that asserts that a `Instructor` is an `instanceof` a `Person`.\n\t* Create a `testTeach` method that ensures when an `Instructor` invokes the `teach` method, a respective student's `totalStudyTime` instance variable is incremented by the specified `numberOfHours`.\n\t* Create a `testLecture` method that ensures when an `Instructor` invokes the `lecture` method, a respective array of students' `totalStudyTime` instance variables is incremented by `numberOfHours/students.length`.\n\n\n-\n### Part 6.1 - Create `People` class\n* Create a `People` class.\n\t* The class should instantiate a `List` field of `Person` objects named `personList`.\n\t* The class should define a method named `add` which adds a `Person` to the `personList`.\n\t* The class should define a method named `findById` which makes use of a `long id` parameter to return a `Person` object with the respective `id` field.\n\t* The class should define a named `contains` which makes use of a `Person person` parameter to return `true` if the `personList` contains the respective `Person` object.\n\t* The class should define a method named `remove` which makes use of a `Person person` parameter to remove a respective `Person` object.\n\t* The class should define a method named `remove` which makes use of a `long id` parameter to remove a `Person` object with the respective `id` field.\n\t* The class should define a named `removeAll` which clears our `personList` field.\n\t* The class should define a method named `count` which returns the size of `personList`.\n\t* The class should define a method named `toArray` which returns an array representation of the `personList` field.\n\t* The class should implement `Iterable\u003cE\u003e` and define a method named `iterator` which makes use of the `personList` field to generate a new a `Iterator\u003cE\u003e`.\n\t\n-\n### Part 6.0 - Test `People`\n* Create a `TestPeople` class.\n\t* Create a `testAdd` method which ensures that our `personList` in our `People` class populated with respective `Person` objects following invokation of the `add` method.\n\t* Create a `testRemove` method which ensures that the `personList` in a `People` object is **depopulated** with a respective `Person` object following the invokation of the `remove` method.\n\t* Create a `testFindById` method which ensures that a respective `Person` object with a respective `id` field is returned upon invokation of the `findById` method on a respective `People` object.\n\n\n-\n### Part 7.1 - Create `Students` singleton\n* **Note:** The creation of this class will demonstrate an implementation of [singleton design pattern](https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples#eager-initialization).\n* Create a `Students` class.\n\t* The class should be an _unextendable_ subclass of the `People` class.\n\t* The class should _statically instantiate_ a `final` field named `INSTANCE` of type `Students`.\n\t* The class should define a _private nullary constructor_ which populates the `INSTANCE` field with respective `Student` representations of your colleagues.\n\t\t* Each student should have a _relatively_ unique `id` field.\n\t* The class should define a `getInstance` method which returns the `INSTANCE` field.\n\t\n\t\n\n-\n### Part 7.0 - Test `Students` singleton\n* Create a `TestStudents` class.\n\t* Create a `test` method which ensures that each of the students in your current cohort are in your `Students` singleton.\n\n\n\n-\n### Part 8.0 - Create and Test `Instructors` singleton\n* Use `Part 7` as a reference.\n* Create a `Instructors` singleton which represents the set of instructors at ZipCodeWilmington.\n* Create a `TestInstructors` class.\n\n\n-\n### Part 9.1 - Create `ZipCodeWilmington` Class\n* Create a `ZipCodeWilmington` singleton.\n\t* The class should declare a field that references the instance of `Students` called `students`.\n\t* The class should declare a field that references the instance of `Instructors` called `instructors`.\n\t* The class should define a method `hostLecture` which makes use of a `Teacher teacher, double numberOfHours` parameter to host a `lecture` to the composite `personList` field in the `students` reference.\n\t* The class should define a method `hostLecture` which makes use of a `long id, double numberOfHours` parameter to identify a respective `Instructor` to host a `lecture` to the composite `personList` field in the `students` reference.\n\t* The class should define a method `getStudyMap` which returns a \u003cu\u003enew instance\u003c/u\u003e of a _mapping_ from `Student` objects to `Double` objects, representative of each respective student's `totalStudyTime`.\n\n-\n### Part 9.0 - Test `ZipCodeWilmington`\n* Create a `TestZipCodeWilmington` class.\n\t* Create a `testHostLecture` method which ensures that each of the `Student`'s `totalStudyTime` instance variable is incremented by the specified `numberOfHours` upon invoking the `hostLecture` method.\n\n\n\n\n\n\n\n\n\n-\n# Notice the Design Flaw - Odd Casting Issues\n* You may have noticed that the `findById`, and `hostLecture` methods require an intermediate [casting trick](https://stackoverflow.com/questions/5289393/casting-variables-in-java).\n* To remedy this issue, we can _generify_ the `People` class.\n\n-\n### Part 10.1 - Modify `People` class\n* [Parameterize](https://stackoverflow.com/questions/12551674/what-is-meant-by-parameterized-type) the `People` signature to enforce that it is a container for objects of type `E` such that `E` is a subclass of `Person`.\n* Modify the class signature to declare this class _abstract_.\n\t* An [abstract class](http://www.javacoffeebreak.com/faq/faq0084.html) cannot be instantiated; Its concrete implementation is deferred to its subclass.\n* Modify `people` field to enforce that is a container of objects of type `E`.\n* Modify the `add` method to ensure that it handles object of type `E`.\n* Modify the `findById` method to ensure that it returns an object of type `E`.\n* Modify the `getArray` method signature by declaring it `abstract` of return tyoe `E`.\n\t* An abstract method is a subclass's contractual agreement to the deferment of an implementation of a respective method.\n\n-\n### Part 10.2 - Modify `People` subclasses\n* Modify the `Students` class signature to ensure that it is a subclass of `People` of parameterized type `Student`.\n* Modify the `Instructors` class signature to ensure that it is a subclass of `People` of parameterized type `Instructor`.\n* Provide concrete implementations of the `getArray` method in each of these classes.\n\n-\n### Part 10.3 - Refactor `ZipCodeWilmington` class\n* Refactor the `hostLecture` method in the `ZipCodeWilmington` class by removing any intermediate _casting trick(s)_.\n\n-\n### Part 10.0 - Test refactored classes.\n* Ensure that the `TestStudents`, `TestInstructors`, `TestPeople`, `TestZipCodeWilmington` classes were not affected by the refactor.\n\n\n\n\n\n\n-\n# Notice the Design Flaw - Non-Intuitive Orientation\n* You may have noticed that `findById` makes it difficult to intuitively identify _which_ `Person` object is being returned. To remedy this issue, we can make use of an `enum` which manipulates a composite `instructor` object.\n\n-\n### Part 11.1 - Create `Educator` enum\n* Create an enum named `Educator`.\n\t* The enum should implement `Teacher`.\n\t* The enum should have an enumeration for each of the instructors represented in the `Instructors` class.\n\t* Upon construction each enumeration of the enum should instantiate a respective `Instructor` and assign it to a final `instructor` field upon construction. The `instructor` should be added to the `Instructors` singleton.\n\t* Calls to the `teach` and `lecture` method should be deferred to the composite `instructor` reference.\n\t* The enum should have a `double timeWorked` field which keeps track of the hours that the `Educator` has taught.\n\n-\n### Part 11.0 - Test `Educator`\n* Use `Part 5` as a reference.\n\n\n-\n### Part 12.0 - Test `ZipCodeWilmington`\n* Ensure the `hostLecture` method can handle objects of type `Educator`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fmaven.learnerlab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzipcodecore%2Fmaven.learnerlab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fmaven.learnerlab/lists"}