Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class StringImproved public class StringImproved extends java.lang.Object This program replaces the string class with a mutable string. This class represents a character array and provide

Class StringImproved public class StringImproved extends java.lang.Object This program replaces the string class with a mutable string. This class represents a character array and provide functionalities need to do basic string processing. It contains an array of characters, representing a textual string. Overview In Java, Strings are a great device for storing arrays of characters. One limitation of Strings in Java, however (there is always at least one), is that they are immutable (ie. they cannot be changed once created). Your mission is to create a mutable String Class (called StringImproved) with some clever features. You will also need to ensure that your program is bug free. Your StringImproved Class should be uncrashable as possible. If your code detects faulty/incorrect input it should handle it as instructed in this java API Data Structure To make your life easier you will be provided with an API specification (just like the JavaDocs you use for your programming). You must use a char array to store your String in your Class. You are not permitted to use any collection Classes in this assignment. You will need to implement the entire class based on the API specification. This class will encapsulate all the functionality required. Testing A test program is also provided for you to use. Please read it carefully as you will be expected to generate your own in assignment 2. Use the test driver as a starting point to test your Class as thoroughly as possible. Note that the marker reserves the right to test more conditions if they think of them. How to Do The Assignment I suggest you do your assignment in the following order Create all the method signatures in the StringImproved Class. Each method should just be blank (with a return null or -1 if necessary). Compile and make sure that the program works (well, technically it won't because the methods are empty, but make sure it compiles with no error). Write the constructors. Test. Write the length method. Test. Write the charAt method. Test. Write the endsWith method. Test. Write the toLowerCase method. Test. Write the toUpperCase method. Test. Write the lastIndexOf method. Test. Write the increaseArray method. Test (note there is no provided test you will need to do it). Write the shrinkArray method. Test (note there is no provided test you will need to do it). Write the contains method. Test. Write the substring method. Test. Write the insert method. Test. Write the append method. Test. Write the deleteSubString int int method. Test. Write the deleteSubString string method. Test. Write the deleteCharAt method. Test. Write the prepend method. Test. Write the replaceString method. Test. Write the sort (advanced students) method. Test. Note that when you add functionality you may have to add test scenarios to other test methods to ensure you have covered all the possibilities. Additional Requirement. In addition to what is above there are a number of requirements for this assignment. Most of these are to introduce interesting problems for you to solve and must be obeyed. As you are programming you will also need to comment your code thoroughly in each of your methods. Whenever you use a String class (for example passed as a parameter) you can only use the charAt() method of String to get content. Sorry we can't make this too easy. The char array in your structure must always have only the space that is required. You are not permitted to use any String methods in this class. If you use a String method you will get zero for the offending method. There is one exception you are permitted to use the Strings toCharArray method How We Will Mark Your Assignment. We will run javadoc on your code to see if your code generates the API correctly. We will read your code to look for style and commenting problems. We will use the test driver to test your testing code. Marking Scheme 75 Percent for it working totally correct (eg no issues with the testing system) 25 Percent for commenting/style of code etc... Hint: Many of the more complicated methods can use the easier methods to do part of their job. For instance if you have a method to delete some string you can use contains and delete (by index) together to achieve your aim. Date 20180501 Version: 1.3 Author: G Stewart Von Itzstein Field Summary Fields Modifier and Type Field and Description content (package private) char[] The storage for the characters in the StringImproved class. Constructor Summary Constructors Constructor and Description StringImproved() Constructor to create a character array with the initial contents of nothing. StringImproved(char newChar) Constructor to create a character array with the initial contents of the supplied char. StringImproved(char[] newString) Constructor to create a character array with the initial contents of the supplied char array. StringImproved(java.lang.String newString) Constructor to create a character array with the initial contents of the supplied java.lang.String. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean append(java.lang.String newString) Append the nominated string to the StringImproved object. char charAt(int location) Get the character at the specified index. int contains(java.lang.String subString) Checks if the current StringImproved contains the nominated subString. boolean deleteCharAt(int delChar) Delete the character at the nominated position. int deleteSubString(int start, int finish) Delete the substring nominated by the index parameters. int deleteSubString(java.lang.String delSubString) Delete the nominated string from the StringImproved object. boolean endsWith(java.lang.String subString) Check if the StringImproved object ends with the nominated string. private boolean increaseArray(int newSize) Increase the capacity of the array to accommodate a different size string. boolean insert(java.lang.String insertionString, int index) Insert the nominated string at the index. int lastIndexOf(char ch) Find the last instance of the character in the StringBuffer. int length() Returns the length of the string. boolean prepend(java.lang.String newString) Prepend the nominated string to the StringImproved object. boolean replaceString(java.lang.String oldSubString, java.lang.String newSubString) Replace the nominated string in the StringImproved object with the specified String. private boolean shrinkArray(int newSize) Shrink the capacity of the array to accommodate a different size string. void sort() Advanced Not required to get full marks. subString(int start, int end) java.lang.String Extract a subsection of the character array. toLowerCase() java.lang.String Convert all characters of the character array to lower case. java.lang.String toString() Returns the string representation of the StringImproved object This method is complete so you can see how it goes together. toUpperCase() java.lang.String Convert all characters of the character array to upper case. Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait Field Detail content char[] content The storage for the characters in the StringImproved class. Constructor Detail StringImproved public StringImproved() Constructor to create a character array with the initial contents of nothing. Difficulty 1/10 StringImproved public StringImproved(char newChar) Constructor to create a character array with the initial contents of the supplied char. Difficulty 1/10 Parameters: newChar - Create the StringImproved using the char as the first char in the array StringImproved public StringImproved(char[] newString) Constructor to create a character array with the initial contents of the supplied char array. Difficulty 1/10 Parameters: newString - Create the StringImproved using the char array. StringImproved public StringImproved(java.lang.String newString) Constructor to create a character array with the initial contents of the supplied java.lang.String. Difficulty 1/10 Parameters: newString - The string to create a character array with. Method Detail toString public java.lang.String toString() Returns the string representation of the StringImproved object This method is complete so you can see how it goes together. Overrides: toString in class java.lang.Object Returns: String representation append public boolean append(java.lang.String newString) Append the nominated string to the StringImproved object. Difficulty 1/10 Parameters: newString - The string to append to the existing string. Returns: True if successful false otherwise. charAt public char charAt(int location) Get the character at the specified index. The index is an integer value ranging from 0 to (length - 1), specifying the position of the character in the character array. For example, "w" has an index of 6 inside "Hello world." Normally you would use exceptions to report error but in this case we are going to return \0 in any case where the result will not make sense (e.g. index greater than length) Difficulty 2/10 Parameters: location - The index of the character required. Returns: The character at the specified index. Return \0 in the event of an error. contains public int contains(java.lang.String subString) Checks if the current StringImproved contains the nominated subString. HINT: Think about using two loops. The outer loop checks against each character in your character array. When you detect the first matching letter in the search subString you use an inner loop to check if the rest of the characters match. Difficulty: 10/10 Parameters: subString - The nominated string to search for. Returns: The position of the located substring in the object -1 otherwise. deleteCharAt public boolean deleteCharAt(int delChar) Delete the character at the nominated position. Difficulty 1/10 Parameters: delChar - The position of the character to delete. Returns: Returns true if successful false otherwise. deleteSubString public int deleteSubString(int start, int finish) Delete the substring nominated by the index parameters. Difficulty 5/10 Parameters: start - The first position to start the deletion. finish - The first position after the last character to be deleted. Returns: The start position of the deletion if successful -1 otherwise. deleteSubString public int deleteSubString(java.lang.String delSubString) Delete the nominated string from the StringImproved object. Difficulty 7/10 Parameters: delSubString - The substring to delete. Returns: Returns the index of the deleted substring -1 otherwise. endsWith public boolean endsWith(java.lang.String subString) Check if the StringImproved object ends with the nominated string. Difficulty 6/10 Parameters: subString - The string to check. Returns: true. If found false otherwise. increaseArray private boolean increaseArray(int newSize) Increase the capacity of the array to accommodate a different size string. This method is a private method, to be used internally whenever the size of the array required is different than the current array. This method will not alter the contents of the current character array. This method resizes it to the new size specified. If the new size is smaller than the current size it will fail. Difficulty 3/10 Parameters: newSize - The new size of the array. Returns: True if successful false if not. insert public boolean insert(java.lang.String insertionString, int index) Insert the nominated string at the index. Difficulty 7/10 Parameters: insertionString - The string to insert into StringImproved object. index - The position to insert at. Returns: True if successful false otherwise. lastIndexOf public int lastIndexOf(char ch) Find the last instance of the character in the StringBuffer. Difficulty 3/10 Parameters: ch - The character to search for. Returns: The index of the last instance of the nominated character. -1 otherwise. length public int length() Returns the length of the string. The length of the string is the number of characters, digits, and punctuation, including space, in the string. For example, "Hello" has a length of 5, and "Hello world." is length 12. Difficulty: 1/10 Returns: The length of the string. -1 in the event of an error. prepend public boolean prepend(java.lang.String newString) Prepend the nominated string to the StringImproved object. Difficulty 1/10 (if your clever) Parameters: newString - The string to append. Returns: True if successful false otherwise. replaceString public boolean replaceString(java.lang.String oldSubString, java.lang.String newSubString) Replace the nominated string in the StringImproved object with the specified String. Difficulty 10/10 if you do it the hard way 2/10 if you do it the easy way. Parameters: oldSubString - The string to replace. newSubString - The string to insert into the location of the old string. Returns: True if successful false otherwise. shrinkArray private boolean shrinkArray(int newSize) Shrink the capacity of the array to accommodate a different size string. This method is a private method, to be used internally whenever the size of the array required is different than the current array. This method can destroy the contents of the current character array. This method resizes it to the new size specified. If the new size is smaller than the current size it will fail. Difficulty 3/10 Parameters: newSize - The new size of the array Returns: True if successful false if not. sort public void sort() Advanced Not required to get full marks. Feel free to have a go though. Sorts the characters in the StringImproved object using mergeSort. Difficulty 12/10 Must write own code not use bundled code in API subString public java.lang.String subString(int start, int end) Extract a subsection of the character array. The returned string contains characters from the start (inclusive) to the character before end. The existing character array will not be changed after calling this method. For example, calling substring (3, 7) on "Hello World." returns "lo W" You must not use any java classes from the java API for this method. Difficulty 3/10 Parameters: start - The beginning index, inclusive. end - The end index, exclusive. Returns: the specified substring. null in the event of an error toLowerCase public java.lang.String toLowerCase() Convert all characters of the character array to lower case. For all characters in the character array, if it is already lower case, it remains lower case; if it is upper case, it will be converted to lower case. This only applies to characters. Digits and punctuation are not affected. You must not use any java classes from the java API for this method. HINT: There might be a method call in another class that will prove useful (other than the String class) Difficulty 2/10 Returns: The lowercase representation of the string. toUpperCase public java.lang.String toUpperCase() Convert all characters of the character array to upper case. For all characters in the character array, if it is already uppercase, it remains uppercase; if it is lowercase, it will be converted to upper case. This only applies to characters. Digits and punctuation are not affected. You must not use any java classes from the java API for this method. HINT: There might be a method call in another class that will prove useful (other than the String class) Difficulty 2/10 Returns: The uppercase representation of the string.

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago