In this assignment we will implement a vector computation engine that is able to construct vectors

and perform vector computations in the Java programming language. Your task is to implement the

incomplete functions in the provided scaffold code based on the included examples and documentation.

You are encouraged to ask questions on Ed using the assignments category. As with any assignment,

make sure that your work is your own, and you do not share your code or solutions with other students.**Working on your assignment**

You can work on this assignment on your own computer or the lab machines. Students can also take

advantage of the online code editor on Ed. Simply navigate to the assignment page and you are able to

run, edit and submit code from within your browser. We recommend that you use Safari or Chrome.

It is important that you continually back up your assignment files onto your own machine, flash drives,

external hard drives and cloud storage providers. You are encouraged to submit your assignment while

you are in the process of completing it. By submitting you will obtain some feedback of your progress.**Implementation details**

Your task is to implement a vector computation engine based on the included scaffold code and

the examples that are shown below. You can assume only valid input will be tested and that any

commands that use vectors will be defined beforehand. All vectors will have the same length defined

by 1 6 *length *6 100*, *000*, *000. Vector elements are indexed from 0 and can contain values up to and

including the maximum value of long. Our test cases will not cause any integer overflows to occur.

Your program must be contained in the Vector.java and VectorEngine.java files and produce

no errors when compiled using javac on the lab machines and Ed. Your program will be run using

java VectorEngine <length> and read from standard input and write to standard output.

The VectorEngine.java file contains the main entry point method to the program, and is

responsible for managing the list of declared vectors, reading from standard input, delegating input

commands to the respective methods declared in the Vector class and then displaying output. This

functionality has been provided in VectorEngine.java and should not need to be modified.

The Vector.java file contains the scaffold code for the Vector class. Method stubs have been

created for the methods that you are expected to implement. Each of these stub methods contains a

comment with some sample input and output to help you understand how these methods should work.

The Vector class contains some instance variables that you can utilise to improve the performance

of your program. Since each vector is immutable we know that the results of each computation will

never change, so there is no need to calculate the same result multiple times. For example, instead

of calculating the sum every time the getSum method is called, you can instead calculate the sum

once and store the result in the sum instance variable then simply return this value in subsequent calls

to getSum. In addition, based on how each vector is constructed, you may be able to deduce some

results based on a mathematical calculation at the time of construction. For example, suppose a vector

was constructed with the uniform command, then we can immediately deduce the mode of the vector.**Running the program**

The program requires you to specify the length of all vectors used in the current instance of the vector

computation engine. The length is read by the program as a command line argument. For example, if

you wanted every vector to contain 4 elements then you would run the program like this:**$ ****java VectorEngine 4****Commands**

Once the program has started, you are prompted to enter the following commands:

• **bye **– Terminates the program.

• **help **– Displays the syntax of each command.

• **set **– Creates a new vector with the given key.

• **show **– Displays the vector with the given key.

• **compute **– Displays the result of a computation.

Introduction to Programming Page **2 **of 8

INFO1103**set ****command**

The **set **command has the following syntax: **set <key> = <operation> <args...>**

• **key **– A string with no spaces that will be used to identify the vector.

• **operation **– The operation used to generate the vector.

• **args **– One or more optional arguments that can be passed to the operation.

Valid operations are:

• **random <seed>**

Generates a new vector where each element is a random integer between 0 and 100 inclusive

using the seed value. Generated using the java.util.Random random number generator.

• **uniform <value>**

Generates a new vector where each element is set to the given **value**.

• **sequence <start> <step>**

Generates a new vector where each element is a value of a sequence of integers starting at**start **and every next value is incremented by **step **which can be both positive and negative.

For example, a sequence starting at 2 that has a step 2 would be:**2 4 6 8 10 12 ...**

• **pq <start>**

Generates a new vector that consists of a sequence of pq numbers. First number in the vector

should be **start **when pq or the next pq number that comes after.

• **prime <start>**

Generates a new vector that consists of a sequence of prime numbers. First number in the vector

should be **start **when prime or the next prime number that comes after.

• **abundant <start>**

Generates a new vector that consists of a sequence of abundant numbers. First number in the

vector should be **start **when abundant or the next abundant number that comes after.

• **composite <start>**

Generates a new vector that consists of a sequence of composite numbers. First number in the

vector should be **start **when composite or the next composite number that comes after.

Introduction to Programming Page **3 **of 8

INFO1103

• **cloned <key>**

Generates a new vector with the same elements of the given vector.

• **sorted <key>**

Generates a new vector with elements of the given vector in ascending order.

• **shifted <key> <amount>**

Generates a new vector with elements of the given vector shifted right n places.

For example:

[1*, *2*, *3*, *4] shifted right by 1 place would be [4*, *1*, *2*, *3].

[1*, *2*, *3*, *4] shifted right by 2 places would be [3*, *4*, *1*, *2].

[1*, *2*, *3