Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program assignment: Build an ADT for vectors A vector x consists of n real components [X1, X2, ..., Xv]. The operations between two vectors x
Program assignment: Build an ADT for vectors
A vector x consists of n real components [X1, X2, ..., Xv]. The operations between two vectors x = [X1, X2, [y, y2, ..., yu) are defined as follows: .., X.) and y addition [x: + Y, x2 + y2, ..., x, + y] subtraction [X1 - Y, x2 - y2 X, -y] dot-product x.y = x1 * y + x2 * y2 + ... + xn * yn equivalence =y if (x1 = y, and x2 = y, and ... and x. = yn) scalar-product s*x= [s * x1, S X2, s*x], where s is a real number. absolute-value | x | = V(x.x) (square root of the dot-product) 1. You should have two constructors: a. One constructor, with parameter (double [] initvalues), where initvalues [] is an array of primitive data type double containing the initialization values of the new MyVector object. b. The copy constructor. 2. You should have a size () function which returns the number of elements in a MyVector object. It would be used, for example, as: length = x.size(), where x is a MyVector object and length is an int. 3. You should have an accessor function get() which returns the component (a double) at some index of a MyVector object. It would be used, for example, as: d x.get (index), where x is a MyVector object and d is a double. 4. You should have member functions for arithmetic: plus () (for addition) and minus () (for subtraction), returning new MyVector objects. They would be used, for example, as: x = y.plus (z), where x, y, z are MyVector objects. 5. You should have a member function for scaling: scaledBy (), which returns a new MyVector object. It would be used, for example, as: x = y.scaledBy (d), where x and y are My Vector objects, and d is a double. 6. You should build a dot product function: dot (). It would be used, for example, as: d = x.dot(y), where x and y are My Vector objects, and d is a double. 7. You should create an absolute value function: abs (). It would be used, for example, as: x.abs(), where x is a MyVector object and d is a double. 8. You should override the toString() method for display on System.out and the equals() method. d = Create a Java project project1 and a package packagel. Call your class MyVector. Define a second class containing a main method that exercises the class MyVector as an application. That is, a main method that runs through a selection of arithmetic and logical operations and uses MyVector output. The two classes should be saved in two different files. Your class MyVector should keep the vector in an ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started