Lab Assignment #0

Objective: This assignment will help you review the ArrayList class as a type-safe generic data type.

Program assignment: Build an ADT for vectors.

Your program should have the following header:

A vector x consists of n real components [x1, x2, …, xn]. The operations between two vectors x = [x1, x2, …,

xn] and y = [y1, y2, …, yn] are defined as follows:

addition [x1 + y1, x2 + y2, …, xn + yn]

subtraction [x1 – y1, x2 – y2, …, xn – yn]

dot-product x • y = x1 * y1 + x2 * y2 + … + xn * yn

equivalence x == y if (x1 = y1 and x2 = y2 and … and xn = yn)

scalar-product s * x = [s * x1, s * x2, …, s * xn], where s is a real number.

absolute-value | x | = (x • x)

1. You should have two constructors:

a. One constructor, with parameters (double [ ] init values), where init values are

the initialization values for the new vector.

b. The copy constructor.

2. You should have an accessor function for the k-th components of a vector.

3. You should have member functions for arithmetic: plus() and minus() which, for example, would

be used as: x = y.plus(z), where x, y, and z are MyVector objects.

4. You should have a member function for scaling: scaled()which, for example, would be used as:

x = y.scaledBy(s), where x and y are MyVector objects, and s is a real number.

5. You should override the toString() method for display on System.out

6. You should override the equals() method.

7. You should create an absolute value function: abs()

8. You should build a dot product function: dot()

Design specifications

• Create a Java project project0 and a package package0.

• 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