QuestionQuestion

After you have completed your recursive MyStringBuilder2 class, you will test it with 2 main programs:
1)    Assig3.java A3Out.txt – This main program is identical to Assig2.java except for the substitution of MyStringBuilder2 in place of MyStringBuilder. Thus, it should produce the same output.
2)    Assig3B.java – This main program is the same as Assig2B.java with the addition of a 4th test case, which you must add for your MyStringBuilder2 class.

Make sure you submit ALL of the following in your single .zip file to get full credit:
1)    All of the files that you wrote, well-formatted and reasonably commented:
    a)    MyStringBuilder2.java (recursive version)
    b)    Assig3B.java
    c)    Any other Java files that you may have also written
2)    The test driver program, unchanged from how you downloaded it:
    a)    Assig3.java
3)    A short, well-formatted analysis of your Assig3B.java results, specifically focusing on the difference in average run-time for the methods with MyStringBuider vs. MyStringBuilder2.
4)    Your completed Assignment Information Sheet. Be sure to help the TA with grading by clearly indicating here what you did and did not get working for the project.

As with Assignments 1 and 2, the idea from your submission is that your TA can compile and run your programs WITHOUT ANY additional files, so be sure to test them thoroughly before submitting them. Some of the MyStringBuilder2 methods are VERY challenging recursively. If you cannot get the programs working as given, clearly indicate any changes you made and clearly indicate why (ex: "I could not get the indexOf() method to work, so I eliminated code that tested it") on your Assignment Information Sheet [one test the TA may do is to compile your MyStringBuilder2.java file with a different copy of Assig3.java from the one you submitted – so if you modified Assig3.java in any way in order to get your program to work, it is essential that you state as much in your Assignment Information Sheet].

Extra Hint for indexOf() method: The iterative version of this method had nested loops, which makes the recursive version trickier. If you have trouble incorporating the functionality into a single recursive method, you may want to consider using two separate recursive methods – one to progress down the MyStringBuilder2 looking for a match and one to test for a match starting at the current location

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

// CS
// Read this class and its comments very carefully to make sure you implement
// the class properly. Note the items that are required and that cannot be
// altered! Generally speaking you will implement your MyStringBuilder2 using
// a singly linked list of nodes. See more comments below on the specific
// requirements for the class.

// For more details on the general functionality of most of these methods,
// see the specifications of the similar method in the StringBuilder class.
public class MyStringBuilder2
{
// These are the only three instance variables you are allowed to have.
// See details of CNode class below. In other words, you MAY NOT add
// any additional instance variables to this class. However, you may
// use any method variables that you need within individual methods.
// But remember that you may NOT use any variables of any other
// linked list class or of the predefined StringBuilder or
// or StringBuffer class in any place in your code. You may only use the
// String class where it is an argument or return type in a method.
private CNode firstC; // reference to front of list. This reference is necessary
// to keep track of the list
private CNode lastC; // reference to last node of list. This reference is
// necessary to improve the efficiency of the append()
// method
public int length; // number of characters in the list

// You may also add any additional private methods that you need to
// help with your implementation of the public methods.

// Create a new MyStringBuilder2 initialized with the chars in String s
public MyStringBuilder2(String s)
{
if(s.length() == 0)
{
firstC = null;
lastC = null;
length = 0;
return;
}
length = s.length();
firstC = nodeBuild(s.toCharArray(), 0);
}

private CNode nodeBuild(char[] s, int index)
{
if(index >= s.length)
return null;
else{
CNode node = nodeBuild(s, index+1);
CNode curNode = new CNode(s[index], node);
if(node == null)
lastC = curNode;
return curNode;
}
}
// Create a new MyStringBuilder2 initialized with the chars in array s
public MyStringBuilder2(char [] s)
{
if(s.length == 0)
{
firstC = null;
lastC = null;
length = 0;
return;
}
length = s.length;

firstC = nodeBuild(s, 0);
}

// Create a new empty MyStringBuilder
public MyStringBuilder2()
{
firstC = null;
lastC = null;
length = 0;
}

// Append MyStringBuilder2 b to the end of the current MyStringBuilder, and
// return the current MyStringBuilder. Be careful for special cases!
public MyStringBuilder2 append(MyStringBuilder2 b)
{
MyStringBuilder2 newString = new MyStringBuilder2(b.toString());
if(newString.length == 0)
return this;
if(length == 0)
{
firstC = newString.firstC;
lastC = newString.lastC;
length = newString.length;
}...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$38.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats