Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi please edit the java code on the left.(do not change whats given) A MathVector object will be passed to your method. Return its contents

image text in transcribedHi please edit the java code on the left.(do not change whats given)

A MathVector object will be passed to your method. Return its contents as a String. If you look in the file MathVector.java you'll see there is a way to output the contents of a MathVector object as a String. This makes it useful for displaying to the user. a 1- import java.util. Random; 2 import java.util.stringJoiner; 3 4- public class preLabc { 5 public static String myMethod(Mathvector inputvector){ 7 8 String vectorstringvalue = new String(); // empty string object 9 10 System.out.println("here is the contents object, inputvector: " + inputvector); 11 12 // get a string out of that Mathvector object. Do it here. On the next line. 13 14 15 // return the double value here. 16 return vectorstringvalue; 17 18 } 19 2e } * Returns a String representation of this vector. The String should be in the format "[1, 2, 3]" * @return a String representation of this vector * capivote **DO NOT** use the built-in {@code Arrays.toString() method. */ @Override public String toString() { var sj = new StringJoiner(",", "1", ")"); for (var e : array) { sj.add(String.valueof(e)); } 1 return sj.toString(); You might have noticed that there's an override term there. That's because many objects already have a "toString" method associated with them... because Java was designed to include them by default. Here, the override tells Java "I know, I know. You already have a toString that you'd assign here. But it's not good enough. Here's a better one for this particular kind of object." It's a little bit like saying "Most humans have two legs. So, by default, I'll give everyone two legs. But sometimes we override that and give no legs, or just one leg to a person. And sometimes we give them four so that they can be a centaur!" To use this in a println() method, just name your object. The toString() method will be called implicitly. Or you can just write System.out.println("look!" + myObject.toString()); What to reproduce this on your own machine? Here are some important files: preLabc.java (fill this in) MathVector.java (the class with all the methods that the student should explore) MyTest.java (the JUnit testing file. Student can use this on their own computer if they wish)

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions