-
Notifications
You must be signed in to change notification settings - Fork 1.6k
f #1780
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
base: master
Are you sure you want to change the base?
f #1780
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public class ArrayList<T> implements List<T> { | ||
| @Override | ||
| public void add(T value) { | ||
|
|
||
| private static final int DEFAULT_SIZE = 10; | ||
| private Object[] elementData; | ||
| private int size; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no resize/grow helper method. The checklist explicitly requires: "Resize the array in a separate method." Add a private method that grows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main.java incorrectly imports |
||
| @Override | ||
| public void add(int index, T value) { | ||
| if (elementData.length == size) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation never throws the required custom exception for invalid indexes. The description requires: "Throw custom |
||
| elementData = ; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax error: |
||
| } | ||
| elementData[index] = value; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall missing use of |
||
| size = size + 1; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -38,7 +47,7 @@ public T remove(T element) { | |
|
|
||
| @Override | ||
| public int size() { | ||
| return 0; | ||
| return size; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Main { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The internal storage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import violates the checklist: "Don't use Objects, Arrays, or any other util class." You also use Arrays.copyOf and Arrays.toString below; remove this import and avoid java.util.Arrays usage in favor of allocating a new backing array and using System.arraycopy (and building toString using elements up to size). |
||
| public static void main(String[] args) { | ||
| ArrayList | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checklist requirement: "Resize the array in a separate method." There is no resize/grow method in this class. Add a private method to handle resizing, computing new capacity as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main.java imports |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The internal storage
elementDatais declared but never initialized (no constructor). Initialize it tonew Object[DEFAULT_SIZE]in a constructor so the list has the default capacity required by the task.