Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit #1532

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Tetiana-Hrytsenko
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on the ArrayList implementation! 😊 There are a couple of critical issues that need to be addressed before we can approve the pull request.

  1. Array Growth Logic: The current logic doubles the array size instead of increasing it by 1.5 times as required. Please adjust the logic to multiply the current length by 1.5 to meet the task specifications.

  2. Custom Exception: The ArrayListIndexOutOfBoundsException class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.

Once these issues are resolved, your implementation should be in great shape! Keep up the great work, and don't hesitate to reach out if you need any help. 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

public class ArrayList<T> implements List<T> {
public static final int DEFAULT_CAPACITY = 10;
public static final int ARRAY_GROWTH_VALUE = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ARRAY_GROWTH_VALUE constant is set to 1, but the task requires the array to grow by 1.5 times when it is full. Consider changing the logic in growIfArrayIsFull to multiply the current capacity by 1.5 instead of using a bitwise shift.

Comment on lines 34 to 35
throw new ArrayListIndexOutOfBoundsException("Can't add value to index " + index
+ ". Index is invalid.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ArrayListIndexOutOfBoundsException class is not defined in the provided files. You need to create this custom exception class to meet the task requirements.

private void growIfArrayIsFull() {
if (size == elementData.length) {
Object[] grownElementData = new Object[elementData.length
+ (elementData.length >> ARRAY_GROWTH_VALUE)];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array growth logic is incorrect. The task requires the array to grow by 1.5 times, but the current implementation uses a bitwise shift which effectively doubles the size. Adjust the logic to multiply the current length by 1.5.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job on addressing the issues from the previous review! 🎉 Your implementation of the ArrayList has improved significantly:

  1. Array Growth Logic: You've successfully updated the array growth logic to multiply the current length by 1.5, aligning with the task specifications. This ensures efficient memory usage and performance.

  2. Custom Exception: The inclusion of the ArrayListIndexOutOfBoundsException for handling invalid indices is a crucial addition, enhancing the robustness of your code.

Your solution now meets the task requirements and constraints. While there were initial issues with the array growth logic and the missing custom exception, you've effectively resolved them.

Remember, addressing such issues is a valuable learning experience. Keep up the good work, and continue to refine your coding skills! If you encounter similar challenges in the future, refer back to this solution as a guide. 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines 41 to 42
Object[] grownElementData = new Object[(int) (elementData.length
+ (elementData.length * 1.5))];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for growing the array is incorrect. According to the task requirements, the array size should be increased by multiplying the current length by 1.5. The current implementation adds 1.5 times the length to itself, which is not correct. Please adjust this logic.

Comment on lines 34 to 35
throw new ArrayListIndexOutOfBoundsException("Can't add value to index " + index
+ ". Index is invalid.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ArrayListIndexOutOfBoundsException class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.


private void checkIndexValidation(int index) {
if (index < 0 || index >= size) {
throw new ArrayListIndexOutOfBoundsException("Index is invalid.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ArrayListIndexOutOfBoundsException class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.

Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

public class ArrayList<T> implements List<T> {
public static final int DEFAULT_CAPACITY = 10;
public static final double ARRAY_GROWTH_VALUE = 1.5;
private Object[] elementData;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use your class type parameter T (you'll have to cast in constructor)

size++;
}

private void checkIndexForAdd(int index) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put private methods after public ones

}
}
}
throw new NoSuchElementException("Element not found");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include element in the message

Comment on lines 85 to 91
return remove(i);
}
}
} else {
for (int i = 0; i < size; i++) {
if (element.equals(elementData[i])) {
return remove(i);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 85, 91 - actual action is the same in both clauses - it means you just have to merge two conditions into one
use the same code as in Java's objects.equals (which you can't use directly)

…, included element name to exception message, created new method for checking for equality of elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants