1 import java.util.Random; 2 import java.util.StringJoiner; 3 4 public class preLabC { 5 6- 7 8 9 10 11 12 13 14 15 16 17 | 18 19 20 } public static String myMethod(MathVector inputVector) { String vectorStringValue = new String(); // empty String object System.out.println("here is the contents object, inputVector: " + inputVector); // get a String out of that MathVector object. Do it here. On the next line. } // return the double value here. return vectorStringValue; ▾ Description 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. *Returns a String representation of this vector. The String should be in the format "[1, 2, 3]" * * @return a String representation of this vector * @apiNote **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.value0f(e)); } 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()); ▸
1 import java.util.Random; 2 import java.util.StringJoiner; 3 4 public class preLabC { 5 6- 7 8 9 10 11 12 13 14 15 16 17 | 18 19 20 } public static String myMethod(MathVector inputVector) { String vectorStringValue = new String(); // empty String object System.out.println("here is the contents object, inputVector: " + inputVector); // get a String out of that MathVector object. Do it here. On the next line. } // return the double value here. return vectorStringValue; ▾ Description 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. *Returns a String representation of this vector. The String should be in the format "[1, 2, 3]" * * @return a String representation of this vector * @apiNote **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.value0f(e)); } 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()); ▸
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education