Proposal for a New Java Exercise: Implementing a Custom MyArrayList
Class
Summary
I’d like to propose a new Java exercise for the Exercism Java track called MyArrayList
. This exercise focuses on creating a simplified version of Java’s ArrayList
to give students hands-on experience with arrays, dynamic resizing, and core data structure methods. This project will help students better understand arrays, collections, and object-oriented programming, while building the foundational skills needed for more advanced data structures.
Purpose and Learning Objectives
The MyArrayList
exercise is designed to help students:
- Understand the fundamentals of dynamic data structures.
- Gain proficiency in array resizing, indexing, and implementing typical collection methods.
- Build a foundation for more complex data structures, such as linked lists and stacks.
- Practice object-oriented programming concepts within the context of a custom Java collection type.
This exercise emphasizes practical skills directly applicable to real-world Java programming by exploring the mechanics of Java’s ArrayList
.
Exercise Outline
Task
Students will implement a MyArrayList
class that replicates the core functionality of Java’s ArrayList
. The class will use a standard array internally to manage elements, and students will need to implement dynamic resizing when the array reaches capacity. By building this data structure from scratch, students gain a deeper understanding of the underlying mechanics of Java collections.
Key Methods
Here’s an outline of the primary methods to be implemented:
-
Constructor: Initializes an internal array with a default capacity.
-
Core Methods:
add(T element)
: Adds an element to the end of the list, resizing if needed.get(int index)
: Returns the element at a specified index.set(int index, T element)
: Replaces the element at a specified index.remove(int index)
: Removes and returns an element at a specified index.size()
: Returns the current number of elements.isEmpty()
: Returns true if the list is empty.
-
Search Methods:
contains(T element)
: Checks if a specific element exists in the list.indexOf(T element)
: Returns the first index of a specified element.lastIndexOf(T element)
: Returns the last index of a specified element.
Suggested Test Cases
Test cases should cover both basic functionality and edge cases to ensure robustness. Here are some sample cases:
-
Basic Functionality:
- Adding elements and retrieving them by index.
- Resizing when adding elements beyond the initial capacity.
-
Boundary Conditions:
- Handling out-of-bound indices with appropriate exceptions.
- Testing removal from different positions (first, middle, last).
-
Additional Functionality:
indexOf
andlastIndexOf
for locating elements.- Converting to array and verifying with
toArray
. - Creating sublists and verifying content with
subList
.
Proposed Difficulty Level
For the Java track, I propose that this exercise be classified as Medium. Exercises of this level often involve slightly more detailed implementation, similar to cipher-based exercises like Affine Cipher, Rotational Cipher, and Atbash Cipher. This level will challenge students who have a basic understanding of arrays, exception handling, and OOP concepts but are ready to explore custom data structures.
Interest in Authoring and Guidance
I am also interested in authoring this exercise and would appreciate guidance and feedback on design and difficulty level. The forum’s input on test cases, structure, and any adjustments to difficulty level will be valuable to ensure this exercise aligns with the goals of the Java track.
Conclusion
The MyArrayList
exercise offers a practical and meaningful project for students eager to deepen their understanding of Java arrays and collection implementation. It provides a strong foundation for future exercises involving more complex data structures.
Thank you for considering this proposal! I’m excited to collaborate on refining it to meet the needs of the Exercism Java track and help students build a solid understanding of Java’s foundational data structures.