Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MyStringBuilder.java Starting code // For more details on the general functionality of most of these methods, // see the specifications of the similar method in

image text in transcribed

MyStringBuilder.java Starting code

// 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 MyStringBuilder { // These are the only two 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 // 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 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 MyStringBuilder initialized with the chars in String s // Note: This method is implemented for you. See code below. Also read // the comments. The code here may be helpful for some of your other // methods. public MyStringBuilder(String s) { if (s == null || s.length() == 0) // special case for empty String { firstC = null; length = 0; } else { firstC = new CNode(s.charAt(0)); // create first node length = 1; CNode currNode = firstC; // Iterate through remainder of the String, creating a new // node at the end of the list for each character. Note // how the nodes are being linked and the current reference // being moved down the list. for (int i = 1; i  

Assign2.java File

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed 

A2Out.txt File

Testing constructor methods this is a string another string Testing copy constructor another string Testing Append methods this is a string another string this is a string another string and another this is a string another string and another another string this is a string another string and another another string!! In reverse: !!gnirts rehtona rehtona dna gnirts rehtona gnirts a si siht Testing for independence of strings this is a string another string and another another string!! another string different strings? another string Special case append to empty string ...appending data Testing charAt method another string Testing delete method we build a string of everything we build everything build everything build In reverse: dliub Testing deleteCharAt method Xhere is a funney little stringh here is a funney little stringh here is a funny little stringh here is a funny little string here is a funny little string b1 is now empty: Testing indexOf method In 'who is whoing over in whoville': who was found at 0 whoing was found at 7 whoville was found at 22 whoviller was found at -1 wacky was found at -1 In 'xxxxxxxxxxxxxxxxxxxy': xxxxxx was found at 0 xxxxxy was found at 14 y was found at 19 Testing insert and replace methods this is very cool Wow, this is very cool Wow, this is very cool as a cucumber! In reverse: !rebmucuc a sa looc yrev si siht ,woW nospaceshere n o s p a c e s h e r e Wow, this is seriously cool as a cucumber! Wow, this is seriously cool as a watermelon! Crikey, this is seriously cool as a watermelon! length is 47 Testing substring method this assignment is hard work Testing MyStringBuilder return types Hello there StringBuilder fans! Hello there CS0445 warriors! 

bl. delete {9,21}; syatem+out.println(b1): // Deleting fram the frant bl. delete (0,3); syatem+out.println(b1); A/ Deleting "past" the end just deletes to the end bl. delete (5,60}; syatem+out.println(b1); /f Testing revstring( ) method Syatem.out.println("In reverge: "+ bl.revstring()l; System. aut.println(" "nTesting deletecharkt method"l; b1 - new KyStringBuilder ("Xhere is a funney little gtringh"); syatem,out,println(b1); If Delete fram the front bl. deleteCharkt (0); syatem+out,println(b1); /f Delete in middle bl. deleteCharkt (14); syatem+out,println(b1); /f Delete at end bl. deletecharkt (bl . length ( ) -1): syatem,out,println(b1); /f Delete at lacation past the end daes nothing bl. deleteCharkt (40); syatem,out,println(b1): Af Deleting all characters while {bl. lengthi }>0 ) b1, deletecharst (b1, lengtb ()1}; system. aut.println("b1 is now emptyi " + b1); Syatem.out.println("'nTeating indexot method"); b1 = ner NystringBuilder\{ "who is whoing over in whoville"); String 81 - new string( who"); string 82= new string ( "whoing") string 53= new string " whoville"); String sd - new String( whoviller") string 85= new string (7 wacky" 1 ; int i1=b1. indexof (51); int i2=b1,indexOf(82)i int 13=b1,1 ndexor (a3); int i4 = b1.indexof (54); int i5 - bl.index 0f(85); syatem,out,println("In " +b1+";"); system.out.println(s1 + " was found at " + i1): System.out.println(s2 + " was found at " +i2) ? syatem.out.println(s3 + " was found at " +13); system_out.println(s4 + " was found at " + i4): System.aut.println(s5 + " was found at " + i5)? b1= nei KystringBu1lder\{ "xxxxxxxxxxxxxxxxxxsy"); s1= nex string xxx77}; 82 - aew string ( "xxxxxy 7); a3 = nei stringl "y"1; i1 = b1.indexof (s1); i3 = b1.indexof (53); system.out.print1n(s2 + " was found at " +i2); system. out.print1n (83+ " was found at "+13); System. aut.print1n("'nTesting insert and replace methods"); b1 - new KystringBuilder\{ 'thil is cool' } b1,insert (8, "very "); system.out.println(b1); I/ Insert at the front b1.insert (0, "Nons, "); system.aut.println(bl); // Ingert at end b1.insert(b1.length (), as a cucunber!"); System. out, println(b1); System. out, print1n(" "In reverse: " + b1.revstring(1); b2= nerz NystringEuilder( "nospaceshere' 3 ; System.aut,print 1 (b (b); for { 1nt 10;1

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago