Northeastern Illinois University Department of Computer Science CS 207 PROGRAMMING II BONUS ASSIGNMENT (3% OF THE CLASS’S TOTAL SCORE) Instructor: Manar Mohaisen XXXXXXXXXXSummer 2020 Email:...

1 answer below »
I attached the assignment below.



Northeastern Illinois University Department of Computer Science CS 207 PROGRAMMING II BONUS ASSIGNMENT (3% OF THE CLASS’S TOTAL SCORE) Instructor: Manar Mohaisen Summer 2020 Email: [email protected] 3 credits Instructions: 1. Carefully read and understand the material we covered in class and implement most of the complete codes before starting to work on this assignment. 2. Your score will be in the range from 0 (0%) to 100 (3% of the class’s total score). You have to master every line, statement, concept, and comment. 3. Do not rely heavily on tutors/peer leaders/peers to solve the assignment for you. 4. You can join my office hours or ask for a 1:1 appointment. Before doing so, read and understand the material we covered in class. I am willing to spend as long as needed to help you. “Life begins at the end of your comfort zone.” Neale Donald Walsch Define the class Vector that includes the following members: • A private instance variable named value of type double[ ] (A reference variable that refers to an array of doubles). • A no-arg constructor that creates an array (array is an object in Java) of 5 doubles referred to by the instance variable value. • A constructor that takes an array of strings. The elements of the taken array are parsed and assigned to the elements of an array referenced by the instance variable value. The first step is to create an array of doubles which is referred to by the instance variable value. The size of this array is equal to the size of the parameter. • A constructor that takes two integer parameters. The first parameter is the size of the created array referenced by the instance variable value. All the elements of the array are initialized to the value of the second parameter. • A constructor that takes an integer parameter. The parameter is the size of the created array referenced by the instance variable value. • A getter and setter methods of the instance data field value. • The getter method will return the instance data field value. Therefore, the array referenced by the instance variable value might be vulnerable to access and modification outside the class Vector. Implement the getter method so that the returned value is a reference to a copy of the array rather Northeastern Illinois University Department of Computer Science than to the original array. The content of the array referred to by the instance field value is accordingly protected. • A public instance method named getSize that returns the size of the array referenced by the instance variable value. • A public instance method named sum that does not take any argument and returns the sum of the elements of the array referred to by the instance variable value. • A public instance method named average that does not take any argument and returns the average of the elements of the array referred to by the instance variable value. • A public instance method named pow that returns the sum of the squares of the elements of the array referred to by the instance variable value. • A public instance method named centralize that takes no argument and returns no value. The method subtracts the average of the array refenced by value from each element of this array. After centering, the average of the array referenced by value is equal to 0. • A public instance method named normalize that takes no argument and returns no value. The method does the following: o Compute the total power of the array referenced by value (use the instance method pow) o Divide every element of the array referenced by value by the square root of the obtained power in the previous step. • A public static method named toVector that takes an integer 2D array (of any dimensions) and returns a reference to a Vector object. The instance variable value of the returned object refers to an array that contains the non-zero elements of the taken 2D array. • A public static method that takes an array of Vector objects (an array of reference variables each referencing a Vector object) and sort it in a non-decreasing order based on the size of the array referenced by the instance variable value of each object. • A public instance method named printVector that prints the elements of the instance variable value of this object. • Test the functionality of the class Vector.
Answered Same DayJul 07, 2021

Answer To: Northeastern Illinois University Department of Computer Science CS 207 PROGRAMMING II BONUS...

Aditya answered on Jul 08 2021
166 Votes
public class Vector
{
private double arr[];
public Vector()
{
arr = new dou
ble[5];
}

public Vector(String arrString[])
{
int size = arrString.length;
arr = new double[size];
for(int i=0;i {
arr[i] = Double.parseDouble(arrString[i]);
}
}

public Vector(int size,int value)
{
arr = new double[size];
for(int i=0;i {
arr[i] = value;
}
}
public Vector(int size)
{
arr = new double[size];
}
public double[] getArr()
{
return arr;
}
public void setArr(double[] arr)
{
this.arr = arr;
}

public int getSize()
{
return arr.length;
}

public double sum()
{
double sum =0;
for(int i=0;i {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here