Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to complete the class StringUtils, which is below. public static void genGauge(String currentString) { System.out.println(currentString); int c = 0; int l = currentString.length();

You are to complete the class StringUtils, which is below.

public static void genGauge(String currentString) {

System.out.println(currentString);

int c = 0;

int l = currentString.length();

String genGauge = "";

while(c < l) {

genGauge = genGauge + c;

if (c < 9) {c++;}

else {c = 0; l = l - 10;}

}

System.out.println(genGauge);

}

Add the following public static methods:

copy

Write and create method String copy(String currentString, int startPosition, int onePastLastPosition). This method returns a substring of currentString, including startPosition, but ending before onePastLastPosition. For example, copy("abcd", 1, 3) returns the String "bc"

cut

write and Create a method String cut(String currentString, int startPosition, int onePastLastPosition). This method returns a String constructed by starting with currentString, and removes the letters starting with startPosition and stopping before onePastLastPosition. For example, cut("abcd", 1, 3) returns the String "ad"

paste

Create method String paste(String currentString, int insertBefore, String stringToInsert). This method returns the String constructed by inserting stringToInsert into currentString before position insertBefore. For example, paste("ad", 1, "bc") returns the String "abcd"

StringMangle

You are to write and create a class StringMangle that has only a main method. This program allows a user to enter a String that we'll call currentString. It maintains another String that we'll call clipboard. The program asks the user to enter currentString. It then uses a sentinel-controlled loop to ask the user to enter one of four commands:

c - copies part of currentString into clipboard using the copy method above. It asks the user for the starting and one-past the ending positions in currentString.

x - assigns a new value to currentString using the cut method above. It asks the user for the starting and one-past the ending positions in currentString.

v - assigns a new value to currentString using the paste method above to insert the clipboard into currentString. It asks the user for the starting position in currentString.

q - quits the program.

Notes

You may assume that the user enters valid input

Use Scanner's next() method to read the currentString from the user. This means that we won't have spaces in the currentString.

Use StringUtils.genGauge to output currentString to the user. It puts character positions (mod 10) underneath the currentString's characters to help the user enter data. For example, System.out.println(StringUtils.genGauge(currentString));

Sample Output:

Enter a string

fghdeabc

The current string is

fghdeabc

01234567

Enter c to copy, x to cut, v to paste, q to quit

C

Enter the starting position

5

Enter one past the ending position

8

The current string is

fghdeabc

01234567

The clipboard is

abc and it has length of 3

Enter c to copy, x to cut, v to paste, q to quit

v

Enter the position the paste should come before

0

The current string is

abcfghdeabc

01234567890

The clipboard is

abc and it has length of 3

Enter c to copy, x to cut, v to paste, q to quit

c

Enter the starting position

6

Enter one past the ending position

8

The current string is

abcfghdeabc

01234567890

The clipboard is

de and it has length of 2

Enter c to copy, x to cut, v to paste, q to quit

v

Enter the position the paste should come before

3

The current string is

abcdefghdeabc

0123456789012

The clipboard is

de and it has length of 2

Enter c to copy, x to cut, v to paste, q to quit

x

Enter the starting position

8

Enter one past the ending position

13

The current string is

abcdefgh

01234567

The clipboard is

de and it has length of 2

Enter c to copy, x to cut, v to paste, q to quit

q

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Will prices for metals, minerals, and other resources rise?

Answered: 1 week ago