Question: language scala in a package name physics create a Scala class named PhysicsVector with the following: A constructor that takes 3 variables of type Double

language scala

in a package name physics create a Scala class named PhysicsVector with the following:

A constructor that takes 3 variables of type Double named x, y, and z. A method named multiplyByConstant that takes a Double and returns Unit. This

method multiplies x, y, and z by the input.

Be sure to update the state variables of the object when this method is called.

Example: if a vector with x, y, and z of (2.0, 0.0, -1.5) has multiplyByConstant(2.0) called on it, its state will become (4.0, 0.0, -3.0).

A method named addVector that takes a PhysicsVector and returns Unit. This method adds the values of x, y, and z of the input vector to the state variable of the calling vector.

Example: If a vector with x, y, and z of (2.0, 0.0, -1.5) has addVector(otherVector) called on it where otherVector is (-3.5, 0.4, -1.0), its state will become (-1.5, 0.4, -2.5).

Testing: In a package named tests" create a Scala class named "TestVector" as a test suite that tests all the functionality listed above.

Sample Usage

val v1 = new PhysicsVector(1.0, 2.0, -3.0) val v2 = new PhysicsVector(-1.5, -3.5, 6.5)

v1.multiplyByConstant(3.0)

assert(Math.abs(v1.x - 3.0) < 0.0001, v1.x)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!