Purchase Solution

Vector class in Java

Not what you're looking for?

Ask Custom Question

Create a Vector class implementing a number of vector operations as methods along with a testing program to verify the class is working.
1. Create a Vector class incorporating the following features:
a. a constructor taking an array of doubles as an argument
b. a toString method returning proper vector notation, e.g < 1.0, -1.0, 0.0, 2.0 >
c. a method to return the size (number of components) of a vector
d. a method to return the norm of a vector
e. a method unitize that will return a unit vector for a given vector
f. a method scale for computing the product of a scalar and a vector
g. a method add for adding two vectors
h. a method dot for computing the dot product of two vectors
i. a method cross for computing the cross product of two vectors (you can assume the vectors passed to the cross produce method have size 3, ie < i, j, k >
j. some of the methods should be static methods
k. the class should properly handle vectors of different sizes
l. methods working with two vectors should check that the input vectors meet the requirements of the operation and if not should return the vector < -0.0001 > for methods returning vectors or -.0001 for methods returning scalars to indicate this failure

2. Create a separate class, VectorTest, that will demonstrate the use of your Vector class. You must create at least two vectors, and demonstrate the use of each method. When you demonstrate the use of each method, print the results to the console in a manner where the values of the vectors are clear, and the method you called as well as its results are clear.
a. Example output: (this does not illustrate the use of all the methods, your VectorTest class should illustrate the use of all of the methods described above).

myVector1 is: <1.0,2.0,3.0>
myVector2 is: <1.0,1.0,1.0>
The sum of myVector1 and myVector2 is: <2.0,3.0,4.0>
The norm of myVector2 is: 1.73
The dot product of myVector1 and myVector2 is: 6.0

Purchase this Solution

Solution Summary

This solution contains a sequence of method in Vector class and make a test in Java format.

Purchase this Solution

Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.