n this assignment, you will implement a simple class called CustomString. This class represents a more customizable version of a String, with additional attributes and methods.   For example, the CustomString class has a “reverse” method which returns a new string version of the current string where the capitalization is reversed (i.e., lowercase to uppercase and uppercase to lowercase) for the alphabetical characters specified in a given argument. For CustomString “abc, XYZ; 123.”, calling reverse("bcdxyz@3210.") will return "aBC, xyz; 123.".   The CustomString class also has a “remove” method which returns a new string version of the current string where the alphabetical characters specified in a given argument, are removed. For CustomString "my lucky numbers are 6, 8, and 19.", calling remove("ra6") will return "my lucky numbers e 6, 8, nd 19.".   There are 5 methods that need to be implemented in the CustomString class:   getString() - Returns the current setString(String string) - Sets the value of the current remove(String arg) - Returns a new string version of the current string where the alphabetical characters specified in the given arg, are reverse(String arg) - Returns a new string version of the current string where the capitalization is reversed (i.e., lowercase to uppercase, and uppercase to lowercase) for the alphabetical characters specified in the given filterLetters(char n, boolean more) - Returns a new string version of the current string where all the letters either >= or <= the given char n, are removed.     Each method has been defined for you, but without the code. See the javadoc for each method for instructions on what the method is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints and example method calls to help you get started.   For example, we have defined a “setString” method for you (see below) which sets the value of the current string. Read the javadoc, which explains what the method is supposed to do. Then write your code where it says “// TODO” to implement the method. You’ll do this for each method in the program. /** Sets the value of the current @param string value to be set */ public void setString(String string) { // TODO Implement method }   In addition, you will write unit tests to test your method implementations. Each unit test method has been defined for you, including some test cases. First make sure you pass all of the provided tests, then write additional and distinct test cases for each unit test method.   For example, we have defined a “testSetString” method for you (see below) which tests the “setString” method. Pass the tests provided then write additional tests where it says “// TODO”. You’ll do this for each unit test method in the program. @Test void testSetString() { //string should be null to start, before setting it assertNull(this.myCustomString.getString());   this.myCustomString.setString("Good-bye!"); assertEquals("Good-bye!", this.myCustomString.getString());   // TODO write at least 3 additional test cases }     Tips Converting a String to an array of chars in Java: Use the ”toCharArray()” method of a String For example: String myString = “hello”; //arrayOfChars contains ‘h’, ‘e’, ‘l’, ‘l’, ‘o’ Char[] arrayOfChars = myString.toCharArray(); Checking whether a specified char value is a letter in Java: Use “Character.isLetter(char)” For example: //isLetter is true boolean isLetter = Character.isLetter('t'); Checking whether a specified char value is uppercase in Java: Use “Character.isUpperCase(char)” For example: //isUpperCase is true boolean isUpperCase = Character.isUpperCase('T'); Checking whether a specified char value is lowercase in Java: Use “Character.isLowerCase(char)” For example: //isLowerCase is true boolean isLowerCase = Character.isLowerCase('t'); Converting a character to uppercase in Java: Use “Character.toUpperCase(char)” For example: //myChar is ‘T’ char myChar = Character.toUpperCase('t'); Converting a character to lowercase in Java: Use “Character.toLowerCase(char)” For example: //myChar is ‘t’ char myChar = Character.toLowerCase('T'); Comparing characters in Java: You can compare characters like you compare numbers using ==, <, and > For example: char myChar1 = ‘s’; char myChar2 = ‘t’;   //compared is true boolean compared = myChar1 < myChar2

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

In this assignment, you will implement a simple class called CustomString. This class represents a more customizable version of a String, with additional attributes and methods.

 

For example, the CustomString class has a “reverse” method which returns a new string version of the current string where the capitalization is reversed (i.e., lowercase to uppercase and uppercase to lowercase) for the alphabetical characters specified in a given argument. For CustomString “abc, XYZ; 123.”, calling reverse("bcdxyz@3210.") will return "aBC, xyz; 123.".

 

The CustomString class also has a “remove” method which returns a new string version of the current string where the alphabetical characters specified in a given argument, are removed.

For CustomString "my lucky numbers are 6, 8, and 19.", calling remove("ra6") will return "my lucky numbers e 6, 8, nd 19.".

 

There are 5 methods that need to be implemented in the CustomString class:

 

  • getString() - Returns the current
  • setString(String string) - Sets the value of the current
  • remove(String arg) - Returns a new string version of the current string where the alphabetical characters specified in the given arg, are
  • reverse(String arg) - Returns a new string version of the current string where the capitalization is reversed (i.e., lowercase to uppercase, and uppercase to lowercase) for the alphabetical characters specified in the given
  • filterLetters(char n, boolean more) - Returns a new string version of the current string

where all the letters either >= or <= the given char n, are removed.

 

 

Each method has been defined for you, but without the code. See the javadoc for each method for instructions on what the method is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints and example method calls to help you get started.

 

For example, we have defined a “setString” method for you (see below) which sets the value of the current string. Read the javadoc, which explains what the method is supposed to do. Then write your code where it says “// TODO” to implement the method. You’ll do this for each method in the program.

/**

  • Sets the value of the current
  • @param string value to be set

*/

public void setString(String string) {

// TODO Implement method

}

 

In addition, you will write unit tests to test your method implementations. Each unit test method has been defined for you, including some test cases. First make sure you pass all of the provided tests, then write additional and distinct test cases for each unit test method.

 

For example, we have defined a “testSetString” method for you (see below) which tests the “setString” method. Pass the tests provided then write additional tests where it says “// TODO”. You’ll do this for each unit test method in the program.

@Test

void testSetString() {

//string should be null to start, before setting it assertNull(this.myCustomString.getString());

 

this.myCustomString.setString("Good-bye!"); assertEquals("Good-bye!", this.myCustomString.getString());

 

// TODO write at least 3 additional test cases

}

 

 

Tips

  • Converting a String to an array of chars in Java:
    • Use the ”toCharArray()” method of a String For example:

String myString = “hello”;

//arrayOfChars contains ‘h’, ‘e’, ‘l’, ‘l’, ‘o’ Char[] arrayOfChars = myString.toCharArray();

  • Checking whether a specified char value is a letter in Java:
    • Use “Character.isLetter(char)” For example:

//isLetter is true

boolean isLetter = Character.isLetter('t');

  • Checking whether a specified char value is uppercase in Java:
    • Use “Character.isUpperCase(char)” For example:

//isUpperCase is true

boolean isUpperCase = Character.isUpperCase('T');

  • Checking whether a specified char value is lowercase in Java:
    • Use “Character.isLowerCase(char)” For example:

//isLowerCase is true

boolean isLowerCase = Character.isLowerCase('t');

  • Converting a character to uppercase in Java:
    • Use “Character.toUpperCase(char)” For example:

//myChar is ‘T’

char myChar = Character.toUpperCase('t');

  • Converting a character to lowercase in Java:
    • Use “Character.toLowerCase(char)” For example:

//myChar is ‘t’

char myChar = Character.toLowerCase('T');

  • Comparing characters in Java:
    • You can compare characters like you compare numbers using ==, <, and >

For example:

char myChar1 = ‘s’; char myChar2 = ‘t’;

 

//compared is true

boolean compared = myChar1 < myChar2;

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Methods of StringBuilder class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT