Implement a new concat method in the String class you worked on for HW2.  The method should return a new String object that represents the text you would end up with if the argument String were "added onto the end of" this String.  For example, in the code below, the String object answer should represent the text "bookstore" and true should be printed the screen. char[] bookA = {'b', 'o', 'o', 'k'}; char[] storeA = {'s', 't', 'o', 'r', 'e'}; char[] bookstoreA = {'b', 'o', 'o', 'k', 's', 't', 'o', 'r', 'e'}; String book = new String(bookA); String store = new String(storeA); String bookstore = new String(bookstoreA); String answer = book.concat(store); System.out.println(answer.equals(bookstore));     In the text area below, type in your definition of the concat method.  (In other words, type in the code that should replace the //TODO comment.)  Your code cannot call any methods.   public class String {     private char[] data;       public String(char[] value) {         data = new char[value.length];         for(int i = 0; i < value.length; i++)             data[i] = value[i];     }   /* text for other methods not listed for the sake of space */       public String concat(String other) {         // TODO     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 9RQ
icon
Related questions
Question

Implement a new concat method in the String class you worked on for HW2.  The method should return a new String object that represents the text you would end up with if the argument String were "added onto the end of" this String.  For example, in the code below, the String object answer should represent the text "bookstore" and true should be printed the screen.

char[] bookA = {'b', 'o', 'o', 'k'};
char[] storeA = {'s', 't', 'o', 'r', 'e'};
char[] bookstoreA = {'b', 'o', 'o', 'k', 's', 't', 'o', 'r', 'e'};
String book = new String(bookA);
String store = new String(storeA);
String bookstore = new String(bookstoreA);
String answer = book.concat(store);
System.out.println(answer.equals(bookstore));
 
 
In the text area below, type in your definition of the concat method.  (In other words, type in the code that should replace the //TODO comment.)  Your code cannot call any methods.
 
public class String {
    private char[] data;
 
    public String(char[] value) {
        data = new char[value.length];
        for(int i = 0; i < value.length; i++)
            data[i] = value[i];
    }
 
/* text for other methods not listed for the sake of space */
 
    public String concat(String other) {
        // TODO
    }
}
Expert Solution
Step 1

Solution: 

Here is the concat ( ) method.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Function Arguments
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT