Description
Design, specify, and implement a class that is similar to an array of double numbers (name it DoubleArray) except that it automatically grows when needed, and negative indexes are also permitted. The class should include:
– a method to put a double number into the ‘array’ at a specified index. For example, suppose that array in a object of the class. Then argval(3,8, 7) would put the number 3.8 at index 7 of the ‘array’. Since negative indexes are also allowed, the statement arr.put(9,1, -3) would put the number 9.1 at the index -3. If you use the method to update a value in a full array, the array’s size will be doubled.
– The class also includes a method to retrieve the number from a specified index. For example, arr.get(7) would return the value of the number that is currently at index 7 of the “array.” If a user tries to get a value that has not yet been put into the array, then the get method will return the Java constant Double-NaN (which is the way Java represents a double value that is not a real number).
– The class should also have two methods that return the value of the largest and the smallest _indexes_ that have ever been set with the put method. If no numbers have yet been put in the “array,” return the “smaller” index should be Integer.MIN_VALUE and the “largest” index should be Integer. MAX_VALUE.
You are not allowed to use the ArrayList or any helper methods from the Java Array API. However, you are allowed to use System.arraycopy() as an exception. Students will lose 60% of the assignment grade if the code has been implemented differently than what is stated in the assignment description.
Examine the provided driver class and its output to guide the design and implementation of the class. You’ll need to incorporate constructors, helper methods, mutators, and accessors. When you execute the code, ensure that your program generates the output as demonstrated in the sample session.
—
### The Driver:
import java.util.*;
public class DoubleDriver {
public static void main(String[] args) {
// printing array info
DoubleArray myarr = new DoubleArray();
System.out.println(“The size of the array is “+ myarr.size());
System.out.println(“The largest index is ” + myarr.largest());
System.out.println(“The smallest index is ” + myarr.smallest());
System.out.println();
// filling the array
myarr.put(5,5,0);
myarr.put(1,5,1);
myarr.put(220,2);
myarr.put(3,5,3);
myarr.put(5,32,4);
myarr.put(422,5);
myarr.put(5,9,0);
myarr.put(0,5,7);
myarr.put(55,5,8);
myarr.put(9,5,9);
// printing the array again
System.out.println(“The elements in the array are.”);
for (int i = 0; i < myarr.size(); i++) {
System.out.print(myarr.get(i) + ” “);
System.out.println(“n”);
System.out.println(“The largest index in the array is ” + myarr.largest());
System.out.println(“The smallest index in the array is ” + myarr.smallest());
System.out.println();
// filling the array backward
myarr.put(20,4,1);
myarr.put(30,2,2);
System.out.println();
System.out.println(“Again, the elements in the array are.”);
for (int i = 0; i < myarr.size(); i++) {
System.out.print(myarr.get(i) + ” “);
System.out.println(“n”);