Question: * A class that implements a very simplified StringBuilder - like class. This * class will not execute on its own - you will need

* A class that implements a very simplified StringBuilder-like class. This
* class will not execute on its own - you will need to use code provided in
* the TestSimpleStringBuilder.java class to run this code.
*
* @author Miles McGann
* @author No partner
* @version 112624
*
*/
import java.util.ArrayList;
import java.util.List;
public class SimpleStringBuilder {
List list;
private void createEmptyBuilder(){
this.list = new ArrayList>();
}
/**
* constructs an empty SimpleStringBuilder
*/
public SimpleStringBuilder(){
this.createEmptyBuilder();
}
/**
* @param input
*/
public SimpleStringBuilder(String input){
this.createEmptyBuilder();
for (int i =0; i input.length(); i++){
this.list.add(input.charAt(i));
}
}
/**
* @return the value of SimpleStringBuilder as a String
*/
@Override
public String toString(){
String myString ="";
for (int i =0; i this.list.size(); i++){
myString = myString + this.list.get(i);
}
return myString;
}
/**
*
* @param i
* @return the character at position to be checked
*/
public char charAt(int i){
// returns the character at specified index
return list.get(i);
}
/**
* @return the length of the StringBuilder
*/
public int length(){
// return the size of the string
return list.size();
}
/**
* Replaces the character at position i with character c
* @param i
* i index to be replaces
* @param c
* c character to use in replacement
*/
public void replaceCharAt(int i,char c){
// removes the character from the index and add the new character
list.remove(i);
list.add(i, c);
}
/**
* Appends the character c to the end of the StringBuilder
* @param i
* @param c
*/
public void append(char c){
// adds the character to the string
list.add(c);
}
/**
* Inserts the character at position i
* @param i
* index to insert at
* @param c
* character to be inserted
*/
public void insert(int i,char c){
// adds the element at ith position
list.add(i, c);
}
/**
* Deletes the character at position i
* @param i
* index to delete
*/
public void delete(int i){
// removes the character at index i
list.remove(i);
}
}
// this is the test code.. **
* A program that tests the SimpleStringBuilder class created in this lab.
*
* @author Jeremy Morris
* @version 20181101
*
*/
public class TestSimpleStringBuilder {
/**
* A simple program used to test the SimpleStringBuilder class
*
* @param args
*/
public static void main(String[] args){
SimpleStringBuilder myBuilder = new SimpleStringBuilder("Hello World");
System.out.println("String is: "+ myBuilder.toString());
// Code below this comment will not work until you complete the required methods
System.out.println("Length is: "+ myBuilder.length());
System.out.println("Char 3 is: "+ myBuilder.charAt(3));
myBuilder.replaceCharAt(3,'p');
System.out.println("String is: "+ myBuilder.toString());
// Code below this comment will not work until you complete the extra methods
// myBuilder.append('!');
// System.out.println("String is: "+myBuilder.toString());
// myBuilder.deleteCharAt(3);
// System.out.println("String is: "+myBuilder.toString());
// System.out.println("Length is: "+myBuilder.length());
// myBuilder.insert(3,'z');
// System.out.println("String is: "+myBuilder.toString());
// System.out.println("Length is: "+myBuilder.length());
}
}// solve these errors in the photos as well as 18 and 19 that i will write out. Provide a code I can just submit from here
18. delete 'b' from string "abc"
zyLabsUnitTest.java:24: error: cannot find symbol testWord.deleteCharAt(1); ^ symbol: method deleteCharAt(int) location: variable testWord of type SimpleStringBuilder 1 error
19.
your output:
String is: Hello World
Length is: 11
Char 3 is: l
String is: Helpo World
expected output:
String is: Hello World
Length is: 11
Char 3 is: l
String is: Helpo World
String is: Helpo World! -(ln)
String is: Helo World! -(ln)
Length is: 11-(ln)
String is: Helzo World! -(ln)
Length is: 12-(ln)
* A class that implements a very simplified

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!