Question: In JAVA, I need help completing these milestones. Disregard the first milestone, but the other milestones need to be added in the code at the

In JAVA, I need help completing these milestones. Disregard the first milestone, but the other milestones need to be added in the code at the bottom. The two screenshots are what the milestones should be / how to do them. Thank you!

In JAVA, I need help completing these milestones. Disregard the first milestone,but the other milestones need to be added in the code at

Code w Milestones markers: MyArrayList Class (Milestones 2, 3 and 4): public class MyArrayList implements MyListInterface { private int m_size; private Integer m_data[];

public MyArrayList() { m_size = 0; m_data = new Integer[2]; }

public int max_size() { return m_data.length; } public int size() { return m_size; } public void doubleCapacity() { // TODO Milestone 2 } public void halveCapacity() { Integer temp[] = m_data; m_data = new Integer[temp.length/2]; for (int i=0; i

public void add(Integer val) { add(m_size, val); }

public void add(int index, Integer val) { // TODO Milestone 2 }

public void remove(int index) { // TODO Milestone 4 }

public int indexOf(Integer value) { // TODO Milestone 3 // -2 will never be right return -2; }

public Integer get(int index) { // TODO Milestone 2 // This should not return null return null; }

public void set(int index, Integer value) { if (index >= m_size) throw new IndexOutOfBoundsException(); m_data[index] = value; } } MyLinkedList Class (Milestones 5,6,7): public class MyLinkedList implements MyListInterface { private class Node { public Node next; Integer data; public Node(Integer data) { this.data = data; this.next = null; }

public Node(Integer data, Node n) { this.data=data; this.next = n; } }

private Node head, tail; private int m_size; public MyLinkedList() { head = null; tail = null; m_size = 0; }

public Integer get(int index) throws IndexOutOfBoundsException { // TODO Milestone 5 return null; }

public int size() { return m_size; } public void addAtFront(Integer data) { Node newnode = new Node(data); if (m_size == 0) { head = newnode; tail = newnode; } else { newnode.next = head; head = newnode; } m_size ++; }

public void addAtBack(Integer data) { Node newnode = new Node (data); if (m_size == 0) { head = newnode; tail = newnode; } else { tail.next = newnode; tail = newnode; } m_size ++; }

public void add(Integer data) { addAtBack(data); }

public int indexOf(Integer data) { // TODO Milestone 6 return -2; }

public void set(int idx, Integer data) throws IndexOutOfBoundsException { if (idx >= m_size) throw new IndexOutOfBoundsException("Index too large."); Node n = head; for (int i=0; i

public void add(int idx, Integer data) throws IndexOutOfBoundsException { // TODO Milestone 5

} Integer removeFront() throws IndexOutOfBoundsException { if (m_size == 0) throw new IndexOutOfBoundsException("Cannot pop from empty list"); Integer data = head.data; m_size --; head = head.next; if (head == null) { tail = null; } return data; }

Integer removeLast() throws IndexOutOfBoundsException { if (m_size == 0) throw new IndexOutOfBoundsException("Cannot pop from empty list"); Integer data = tail.data; Node n = head; m_size--; if (m_size == 0) { head = null; tail = null; } else { for (int i = 0; i

public void remove(int idx) throws IndexOutOfBoundsException { // TODO Milestone 7 } public Integer front() { return head.data; }

public Integer back() { return tail.data; }

}

Thanks Again!

Milestones The functionality for the above methods is like what we discussed in class (in pseudocode and pictures). The functionality is summarized below: - This method should double the capacity of the MyArrayList. The data in the MyArrayList should not be modified. - We discussed this method in class - The halveCapacity () method is already implemented for you as an example. - Adds the value at the specified index. It should maintain the rest of the data in the List (as discussed in class). - If you attempt to add to an MyArrayList that is filled to maximum capacity, you must call the method. - If the index is greater than the number of elements in the array, you must throw an - Removes the value at the specified index. It should maintain the rest of the data in the List (as discussed in class). - If you attempt to remove data at an index that is >= the number of elements in the array, you must throw an - If after the removal the number of elements in an ArrayList drops below one quarter of the maximum capacity (after the removal has occured), you must call the halveCapacity () method. - Returns the index of the first instance of value in the List. - if value is not in the List, it should return -1. - Returns the value at the specified - If index is greater than or equal to the number of elements in the List, throw an IndexOutOfBoundsException

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!