Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with how to write the new Class Lab1b and how to use vdef from Class Vector that I have. [This is the

I need help with how to write the new Class Lab1b and how to use vdef from Class Vector that I have.

[This is the instruction i have

image text in transcribed

[This is the class Vector]

image text in transcribed

You implement the class Lab1b, which contains only the method main(..). Use Syslem.oul.prinlln(.-) to write a vector or the return value of a method to the console. Implement the following lines that test all methods of Vector. Write out the content of vdef before you create the first instance of Vector. Create the vector v1 using the default constructor and write out its content. Change the coordinates of the default vector vdef to (1.0,2.0,3.0), use the method selToDefaull () of v1, and write out the content of v1. Create the vector v2 with the coordinates (1.0,1.0,2.0) and write out its content. Write out the string "Length: " followed by the length of v1. Initialize the matrix m1 with the elements ((1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0.0, 1.0) ), and write out the ressilt of ealling the method malrixMull(m1) of v1. Initializing a 2D array works in the same way as initializing a 1D array (first part of the lab). The declaration uses double[J] and you initialize it with the construct {{a11,a12,a13},{a21,a22,a23},{a31,a32,a33}} Initialize the matrix m2 with the elements ((1.0,0.0),(0.0,1.0)), and write out the result of calling the method malrixMull(m2) of v1. Initialize the matrix m3 with the elements ((0.0,1.0,0.0),(1.0,0.0,0.0),(0.0,0.0, 1.0) ), and write out the result of malrixMull(m3) of v1. Write the result of adding v1 and v2 to the console. Write the result of subtracting v2 from v1 to the console. Write the result of 2v1 to the console. Write the result of the dot product between v1 and v2 to the console. Write the result of the length comparison of v1 and v2 to the console. Normalize v1 and v2 and write the scalar products of (a) v1 and v2 and (b) v2 with itself to the console. public void set Tobefault() {// setTobefault() sets the values of x,y,z x=vdcfx; y=vdcfy; \} z - vicf.z; public Vector plus(Vector v1, Vector v2) \{ \} return new Vector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); public Vector minus(Vector v) \{ \} return new Vectar(xv.x,yv.y,zv.z); public vector mult(double m) \{ return new Vectar(x+m,y+m,z+m); \} public double mult(Vector v) \{ \} return x+vx+y+vy+z+ v.r; public double length() \{ \} return Nath.sart (x+x+y+y+z+z); public Vector nom() f double len - length(); \} return new Vector( x/ len, y/ len, z/ len); public Vector matrixult(double[][] m) \{ if (m.length 13m[].length 3 ) \{ return this; \} double now x+m[][6]+y+m[1][6]+z+m[2][]; double nowY x+m[][1]+ym[1][1]+zm[2][1] double nowz x+m[][2]+y+m[1][2]+zm[2][2]; return new Vector(new , nowY, nowz); \} public int compareTo(Vector v) \{ double diff - length() - v.length(); if (diff ) ) \{ return 1; f else \{ return e; \} \} public string tostring() \{ return string-farmat(" (%.2f,x.2f,x.2f)n,x,y,z); \} public static void main(String[] args) \{ Vector v1 - new Vector(1,2,3); Vector v2 - new Vector (4,5,6); Vector v3 - v1.plus (v1,v2); \} Systom.ourt.print ln(v3); \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions