Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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: XXXXXXXXXX XXXXXXXXXX3 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
a
ay of doubles).
• A no-arg constructor that creates an a
ay (a
ay is an object in Java) of 5 doubles refe
ed to by
the instance variable value.
• A constructor that takes an a
ay of strings. The elements of the taken a
ay are parsed and
assigned to the elements of an a
ay referenced by the instance variable value. The first step is to
create an a
ay of doubles which is refe
ed to by the instance variable value. The size of this
a
ay is equal to the size of the parameter.
• A constructor that takes two integer parameters. The first parameter is the size of the created
a
ay referenced by the instance variable value. All the elements of the a
ay are initialized to the
value of the second parameter.
• A constructor that takes an integer parameter. The parameter is the size of the created a
ay
eferenced 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 a
ay 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 a
ay rather
Northeastern Illinois University
Department of Computer Science
than to the original a
ay. The content of the a
ay refe
ed to by the instance field value is
accordingly protected.
• A public instance method named getSize that returns the size of the a
ay 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 a
ay refe
ed 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 a
ay refe
ed to by the instance variable value.
• A public instance method named pow that returns the sum of the squares of the elements of the
a
ay refe
ed 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 a
ay refenced by value from each element of this a
ay.
After centering, the average of the a
ay 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 a
ay referenced by value (use the instance method pow)
o Divide every element of the a
ay 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 a
ay (of any dimensions) and
eturns a reference to a Vector object. The instance variable value of the returned object refers to
an a
ay that contains the non-zero elements of the taken 2D a
ay.
• A public static method that takes an a
ay of Vector objects (an a
ay of reference variables each
eferencing a Vector object) and sort it in a non-decreasing order based on the size of the a
ay
eferenced 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 Day Jul 07, 2021

Solution

Aditya answered on Jul 08 2021
154 Votes
public class Vecto
{
private double a
[];
public Vector()
{
a
= new double[5];
}

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

public Vector(int size,int value)
{
a
= new double[size];
for(int i=0;i {
a
[i] = value;
}
}
public Vector(int size)
{
a
= new double[size];
}
public double[] getA
()
{
return a
;
}
public void setA
(double[] a
)
{
this.a
= a
;
}

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

public double sum()
{
double sum =0;
for(int i=0;i.length;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