Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
bartleby

Concept explainers

Question
Book Icon
Chapter 9, Problem 12PC
Program Plan Intro

Miscellaneous String Operations

Program Plan:

The detail of “StringOperationsDemo” class is shown below:

  • In the “main()” method,
    • Declare and initialize the variable and array variable.
    • Call the wordCount() method to display the number of words in string.
    • Call the mostFrequent() method to display the most frequently occurring character.
    • Call replaceSubString() method to replace “the” with “that”.
    • Call arrayToString() method to convert an array to a string.
    • Display the converted string.

The detail of “StringOperations” class is shown below:

  • In the “wordCount()” method,
    • Separate the string using a space delimiter.
    • Return the number of words in string.
  • In the “arrayToString()” method,
    • Convert the array value to string.
    • Return the converted string.
  • In the “mostFrequent()” method,
    • Declare the variable.
    • Convert the String to an array and store into “cArray” variable.
    • Create an integer array variable to store the frequencies of the characters in “cArray” variable.
    • The for loop executes until the frequencies length. If yes,
      • Initialize frequencies elements to “0”.
    • The for loop executes until the array length. If yes, loop executes until the array length. If yes,
      • Check frequency of element and then calculate it.
    • The for loop executes until the frequencies length. If yes,
      • Check the frequencies of elements and determine the most frequent character.
    • Return the most frequent character.
  • In the “replaceSubString()” method,
    • Check the “string2” and “string3” are the same. If yes,
      • Return the string.
    • Create an object for “string1”.
    • Determine the first occurrence of “string2”.
    • The while loop executes until the "index" is not equal to “-1”. If yes,
      • Call the replace() method to replace this occurrence of the substring.
      • Find the next occurrence of “string2”.
    • Return the string.

Blurred answer
Students have asked these similar questions
Complete the class LeetMaker class using String methods. Remember that all the String methods are accessors. They do not change the original String. If you want to apply multiple methods to a String, you will need to save the return value in a variable. Complete the class by doing the following: Print the word in lowercase Replace "e" with "3" (Use the unmodified variable word) Print the changed word In the changed word, replace: "t" with "7" Print the changed word In this newest changed word, replace: "L" with "1" (uppercase L with the number 1). Then, print the final changed word (with all the replacements) Print the length of the word The code to print the original word is already included for you. Do not change that statement.  You will need to use the replace() method multiple times. Then print the final String. Remember that replace is an accessor method; It returns the changed version of the String. If you want to do something with the returned String - like use replace() on…
In some circumstances, a class is reliant on itself. That is, one class's object interacts with another class's object. To accomplish this, a method of the class may accept an object of the same class as a parameter.The String class's concat function is an example of this situation. The method is called by one String object and receives another String object as an argument. Here's an illustration:str3 is equal to str1.concat(str2);The method's String object (str1) appends its characters to those of the String supplied as a parameter (str2). As a consequence, a new String object is returned and saved as str3. Create Java code to implement the conditions given.
Code in Java keep the code as simple as possible do not use arrays nor parseItnt StringBuilder etc keep it very simple.Proper setters, getters, constructors, and toString methods for all of the classes  Class Text This is a text editing class. In its constructor it receives a string. The string will be stored in a field called initialValue using proper setter methods and proper documentation for Each of the methods .  The class also contains another String field called: ”mixedResult” which is only defined globally and will be initialized using a method in the future in the main class namely the mix method.  The public String toToken() method is a method that will use the initialValue field and it for the letter ’p’ or the letter ’A’. If it finds the letter, every element on the left side of the found letter will be stored in another string and returned. For example: If the initialValue was: ”This is a possible resource allocation”. The returning String will be: ”possible resource…

Chapter 9 Solutions

Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)

Ch. 9.3 - Prob. 9.11CPCh. 9.3 - Prob. 9.12CPCh. 9.3 - Prob. 9.13CPCh. 9.3 - Look at the following code: String str1 = To be,...Ch. 9.3 - Prob. 9.15CPCh. 9.3 - Assume that a program has the following...Ch. 9.4 - Prob. 9.17CPCh. 9.4 - Prob. 9.18CPCh. 9.4 - Prob. 9.19CPCh. 9.4 - Prob. 9.20CPCh. 9.4 - Prob. 9.21CPCh. 9.4 - Prob. 9.22CPCh. 9.4 - Prob. 9.23CPCh. 9.4 - Prob. 9.24CPCh. 9.5 - Prob. 9.25CPCh. 9.5 - Prob. 9.26CPCh. 9.5 - Look at the following string:...Ch. 9.5 - Prob. 9.28CPCh. 9.6 - Write a statement that converts the following...Ch. 9.6 - Prob. 9.30CPCh. 9.6 - Prob. 9.31CPCh. 9 - The isDigit, isLetter, and isLetterOrDigit methods...Ch. 9 - Prob. 2MCCh. 9 - The startsWith, endsWith, and regionMatches...Ch. 9 - The indexOf and lastIndexOf methods are members of...Ch. 9 - Prob. 5MCCh. 9 - Prob. 6MCCh. 9 - Prob. 7MCCh. 9 - Prob. 8MCCh. 9 - Prob. 9MCCh. 9 - Prob. 10MCCh. 9 - To delete a specific character in a StringBuilder...Ch. 9 - Prob. 12MCCh. 9 - This String method breaks a string into tokens. a....Ch. 9 - These static final variables are members of the...Ch. 9 - Prob. 15TFCh. 9 - Prob. 16TFCh. 9 - True or False: If toLowerCase methods argument is...Ch. 9 - True or False: The startsWith and endsWith methods...Ch. 9 - True or False: There are two versions of the...Ch. 9 - Prob. 20TFCh. 9 - Prob. 21TFCh. 9 - Prob. 22TFCh. 9 - Prob. 23TFCh. 9 - int number = 99; String str; // Convert number to...Ch. 9 - Prob. 2FTECh. 9 - Prob. 3FTECh. 9 - Prob. 4FTECh. 9 - The following if statement determines whether...Ch. 9 - Write a loop that counts the number of space...Ch. 9 - Prob. 3AWCh. 9 - Prob. 4AWCh. 9 - Prob. 5AWCh. 9 - Modify the method you wrote for Algorithm...Ch. 9 - Prob. 7AWCh. 9 - Look at the following string:...Ch. 9 - Assume that d is a double variable. Write an if...Ch. 9 - Write code that displays the contents of the int...Ch. 9 - Prob. 1SACh. 9 - Prob. 2SACh. 9 - Prob. 3SACh. 9 - How can you determine the minimum and maximum...Ch. 9 - Prob. 1PCCh. 9 - Prob. 2PCCh. 9 - Prob. 3PCCh. 9 - Prob. 4PCCh. 9 - Prob. 5PCCh. 9 - Prob. 6PCCh. 9 - Check Writer Write a program that displays a...Ch. 9 - Prob. 8PCCh. 9 - Prob. 9PCCh. 9 - Word Counter Write a program that asks the user...Ch. 9 - Sales Analysis The file SalesData.txt, in this...Ch. 9 - Prob. 12PCCh. 9 - Alphabetic Telephone Number Translator Many...Ch. 9 - Word Separator Write a program that accepts as...Ch. 9 - Pig Latin Write a program that reads a sentence as...Ch. 9 - Prob. 16PCCh. 9 - Lottery Statistics To play the PowerBall lottery,...Ch. 9 - Gas Prices In the student sample program files for...
Knowledge Booster
Background pattern image
Computer Science
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
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,