Write a class named Assignment2. It must work with the attached Assignment2Driver Java source code file.

For this assignment, we work with an array, a class, a member variable, and member functions, including a constructor. Loops and if() statements are also needed. Some functions are overloaded.

Required elements:

  • A private member variable for an array of integers. This is a reference variable.
  • A constructor that accepts a reference to an array of integers. Use this reference to initialize the member variable.
  • A function named getAverage, which accepts no arguments and returns a double that is the average of the elements in the array.
  • A function named getAverage, which accepts a single integer argument n and returns a double, the average of the first n elements in the array.
  • A function named getRange, which accepts no arguments, which returns an int, which is the range of the elements in the values array. Hint: The easy way to do this is to use two of the other functions.
  • A function named getMaximum, which accepts no arguments and returns the value of the largest element in the array.
  • A function named getMinimum, which accepts no arguments and returns the value of the smallest element in the array.
  • A function named getAll, which accepts no arguments and returns a reference to the array of integers.
  • A function named getValueAt, which accepts an integer argument and returns the value at that index in the array.
  • A function named setValueAt, which accepts two integer arguments: the index, and a new value to store at that index, in that order.

Bonus: Add a function named getStandardDeviation, which returns the standard deviation of the values in the array. Use the formula for the population, not a sample.

All functions must be public and non-static. Public, because I will use Assignment2Driver.java to grade your solution. Non-static because the Assignment2Driver class will create an instance of your class.

Minus 10 points if static appears anywhere in your Assignment2.java file. Minus 10 more points if you have any System.out.print() or System.out.println() statements.

Zero score if your class fails to compile. A program which fails to compile, also fails to run, and thus it accomplishes nothing, hence a 0/100.

Here is some sample output:

The average is 3.75
The average is 4.25
The range is 21
The maximum is 17
The minimum is -4
-1 1 0 17 7 -4 8 2
After set and get: 99
The average is now 16.13
The range is now 103
The maximum is now 99
The minimum is now -4
Standard deviation is 31.908
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.