Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
Problem 4: MyArray: A simple class for manipulating a Java Array
66 points total; individual-only
For this problem, write a class MyArray that provides a series of instance (i.e. non static) methods which will allow a client program to manipulate an array of integers.
The class MyArray will act as a custom data type (i.e. Blueprint class) which you can use to create objects, each one containing its own array of integers that can be manipulated by calling the instance methods of the class.
Begin by downloading the file: MyArray.java, which sets-up the skeleton of your class. Thisclass should contain the following data members inialized with the specified default values provided in the skeleton code:
· SENTINEL, a class level read-only variable used to control user input
■ DEFAULT_SIZE, a class level read-only variable used by the no-argument ccnstructor
· LOWER, a class level read-only variable that represents the smallest possible integer that
can be entered by the user
■ UPPER, a class level read-only variable that represents the largest possible integer that can be entered by the user
. arr, an instance variable which reference the array of integers
· numElements, an instance variable to store how many integers have been added to the array
As you can see the no-argument constructor has been provided. This constructor creates the array of integers and assigns the address of the array to the data member arr. It also initializes the data member numElements to zero, as no elements have been added to the array.
/* File: MyArrays
*
* Author: CS112
*
* Purpose: To create a class that allows you to
* manipulate an array of integers.
*/
import java.util.Arrays;
public class MyArray {
// the sentinel value used to indicate end of input, initialized to -999
// the default size of the array if one is not specified, initialized to 20
// the lower bound of the range of integer elements, initialized to 10
// the upper bound of the range of integer elements, initialized to 50
// a data member to reference an array of integers
// a data member to represent the number of elements entered into the array
// CONSTRUCTORS
// Initializes a MyArray object using default members
public MyArray() {
arr = new int[DEFAULT_SIZE];
numElements = 0;
}
public static void main(String [] args) {
System.out.println("\nUnit Test for MyArray.\n");
// Fill in your unit tests
}
}
Important guidelines:
. The class members must not be changed in any way. You must use the member names as provided or specified.
Your methods must have the exact headers that we have specified, or we won't be able to test them. Note in particular that the case of the letters matters.
lf you are asked to write a method that returns a value, make sure that it returns the specified value, rather than printing it.
.You should not use any Java classes that we have not covered in the lecture notes.
Make sure to do proper validation where necessary. For example, if an expected argument to a method should be positive do not allow for a negative number, and thrown an exception as needed.
.Each of your methods should be preceded by a comment that explains what your methods does and what its inputs are. You should also include a comment at the top of the file.
-More generally, use good programming style. Use appropriate indentation, select descriptive variable names, insert blank lines between logical parts of your program, and add comments as necessary to explain what your code does. See the coding conventions for more detail.
Add the following data members as instance variables of the class:
. sum, represents the sum of all the elements in the array
. min, represents the minimum value of all elements in the array
. max, represents the maximum value of all the elements in the array
. avg, represents the average of all the elements in the array