Question: I already done somehow, but it dose not work right now. // File: MyArrayList.java // Author: (your name here) // Geoffrey Tien/ Rita Ester //

I already done somehow, but it dose not work right now.
// File: MyArrayList.java
// Author: (your name here)
// Geoffrey Tien/ Rita Ester
// Date: September 11, 2017
// Description: to be completed:
// Implementation of a simple container class
// with a (modified) subset of ArrayList functionality
// For a description of the required behaviour
// of some functions, please see
// http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
//
// Please note: In MyArrayList, all elements should be saved in the
// lower indices of the array, so that there are no unused indices
// between 0 and size.
// Assume that the list will contain only positive values
public class MyArrayList
{
// private member attributes
private final int DEF_CAPACITY = 10;
private int capacity; // maximum size of the array
private int[] arr; // underlying array
private int size; // number of items stored
// private member functions
// you may declare any of your own private member functions you need here
// public member functions
// default constructor
// Constructs an empty list with an initial capacity of ten
public MyArrayList()
{
// to be completed
}
// parameterized constructor
// Constructs an empty list with the specified initial capacity
public MyArrayList(int initialcapacity)
{
// to be completed
}
// copy constructor
// Constructs a new list as a deep copy of the specified list
public MyArrayList(MyArrayList sourcelist)
{
// to be completed
}
// Returns the number of elements in this list
public int size()
{
return size;
}
// Returns true if this list contains no elements
public boolean isEmpty()
{
if (size
else return false;
}
// Returns true if this list contains the specified element
public boolean contains(int item)
{
boolean result = false;
// to be completed
// linear search for item
return result;
}
// Returns the index of the first occurrence of the specified element in this list,
// or -1 if this list does not contain the element
public int indexOf(int item)
{
// to be completed
return -1;
}
// Returns the element at the specified position in this list
// or -1 if index is invalid
public int get(int index)
{
// to be completed
}
// Replaces the element at the specified position in this list with the specified element
// Returns the element previously at the specified position
// Do not add, and return -1 if index is invalid
public int set(int index, int item)
{
// to be completed
}
// Appends the specified element to the end of this list
// Returns true when successful
// Note that capacity must be increased to double its size if the array is full
public boolean add(int item)
{
// to be completed
return true;
}
// Inserts the specified element at the specified position in this list.
// Shifts the element currently at that position (if any) and any
// subsequent elements to the right (adds one to their indices).
// Do not add if index is out of bounds.
public void add(int index, int item)
{
// to be completed
}
// Removes the element at the specified position in this list.
// Shifts any subsequent elements to the left
// Returns -1 if index is invalid
public int removeAt(int index)
{
// to be completed
}
// Removes the first occurrence of the specified element from this list, if it is present, then return true.
// If the list does not contain the element, it is unchanged and return false.
public boolean remove(int item)
{
boolean found = false;
// to be completed
return found;
}
// Removes all of the elements from this list.
// The list will be empty after this call returns.
public void clear()
{
size = 0;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// File: CSCI225A1SimpleDriver.java
// Author: (your name here)
// Geoffrey Tien/ Rita Ester
// Date: September, 2017
// Description: Partial test driver for CSCI 225 Spring 2017 Assignment 1
// It is highly recommended to add your own code to test
// as many general and boundary cases as you can for each
// of these functions.
public class CSCI225A1SimpleDriver
{
public static void main(String[] args)
{
System.out.println("CSCI 225 Assignment 1 simple test driver ");
System.out.println("It is recommended for you to add your own test code to this file. ");
System.out.println("Entering test method 1... ");
Test1();
System.out.println("Test 1 done.");
System.out.println("Entering test method 2... ");
Test2();
System.out.println("Test 2 done.");
System.out.println("All tests complete. Exiting...");
}
private static void Test1()
{
// Creating a MyArrayList instance using default constructor
MyArrayList list1 = new MyArrayList();
// Add some items and modify
System.out.print("Adding two items to list1... ");
list1.add(12);
System.out.println("Getting item at index 0. Expected: 12, Got: " + list1.get(0));
list1.add(0, 5);
System.out.println("done.");
System.out.println("Getting item at index 0. Expected: 5, Got: " + list1.get(0));
System.out.println("Getting item at index 1. Expected: 12, Got: " + list1.get(1));
System.out.println("list1 size: " + list1.size());
list1.set(1, 54);
System.out.println("Getting item at index 1. Expected: 54, Got: " + list1.get(1));
System.out.println("list1 size: " + list1.size());
System.out.println("Is list1 empty? " + list1.isEmpty());
System.out.println("Does list1 contain 54? " + list1.contains(54));
list1.add(67);
System.out.println("Index of 67: " + list1.indexOf(67));
}
private static void Test2()
{
// Creating MyArrayList instance using parameterized constructor
MyArrayList list1 = new MyArrayList(3);
list1.add(5);
list1.add(6);
list1.add(7);
list1.add(5);
list1.add(6);
list1.add(7);
// Creating MyArrayList instance using copy constructor
MyArrayList list2 = new MyArrayList(list1);
// remove some items from list1 and check size of both
list1.removeAt(0);
list1.remove(5);
System.out.println("list1 size: " + list1.size());
System.out.println("list2 size: " + list2.size());
System.out.println("Clearing list2 and checking size... ");
list2.clear();
System.out.println("list2 size: " + list2.size());
}
}
CSCI 225-Fall 2017 Assignment I MyArrayList Due: 10pm Tuesday, September 26, 2017 The Java ArrayList is a resizable-array implementation of the Java List interface. The ArrayList has a capacity which can grow automatically as elements are added. For details of the standard ArrayList behaviour, please see http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html In this assignment, you will implement your own MyArrayList class, which imitates a subset of the ArrayList functionality. Whenever the capacity of your array changes as a result of a method call, you must make a deep copy of the array contents to a new array. For details explaining the required behaviour of each function, please refer to the comments written above each method prototype in the supplied skeleton MyArrayList.java file. Download MyArrayList.java and CSCI225A1SimpleDriver.java from C4 Include your name in the comments at the top of your MyArrayList.java file. Complete the implementation of the methods in MyArray List . java that contain the comment /to be completed". Use CSC122 5A1SimpleDriver . java to test your code. It is highly recommended to add your own test methods to CSCI225A1SimpleDriver.java, so that you can thoroughly test both general and special cases for each function (e.g. add/remove/retrieve from an empty list, from a full list, partially full list, from the front/back/middle of the array, from invalid indices, etc.) Method stubs If you are unable to complete the implementation of any method, you may write a stub method. A stub contains in its method body only a default return statement of the appropriate type, so that the file is able to compile without errors Here is an example of a stub for the method public int RemoveAt (int index), which must return an int in order to compile public int RemoveAt (int index) return -1; Deliverables Please upload to C4 before the deadline . Your MyArrayList.java file with all functions completed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
