Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BACKGROUND Strings in Java are important- very often capturing user input involves using a String. For us, a String is one of our first exposures

BACKGROUND

Strings in Java are important- very often capturing user input involves using a String. For us, a String is one of our first exposures to classes and objects in Java. Unlike primitive data types which just hold data, objects can perform different tasks with the data they hold. For instance, a String can convert itself to all uppercase (or lowercase). It can also trim all the leading and trailing whitespace from itself. It can report its length (number of characters). It can see if specific characters are contained in it. There are many things that a String can do - check out the Relevant API for more functionality, as well as Section 4.3 in the textbook.

This software has three phases:

STEP 1: Obtain a phrase from the user

Prompt the user for a phrase and store their input into a String.

STEP 2: Output a menu and capture a choice from the user

Display the menu (as shown in the sample output) and capture the users choice.

STEP 3: Output the result of the operation the user selected

Using if statements (perhaps if-else), perform the indicated task on the phrase the user entered. Note that some tasks (such as choice 6 - substring) may have more than one component.

CLASS NAME: StringLab02.java

NOTES

  • The input phrase for these examples is always this is a test. The test cases that will be used to grade the program contain other phrases, so make sure that your software is not hard-coded to only function for the phrase that is demonstrated here. For example, menu option 2 (charAt) is shown asking for a character between 0 and 13. These values will change when other input phrases are used.

  • You will likely experience a problem using the Scanner after reading in a primitive data type (that is, if you want to read in a String after reading in an int). There is a solution- refer to the Scanner section of the Relevant API (Pro-Tip) or Section 4.4 in the textbook (Quirky Behavior).

  • Recall that an if-else structure will always execute exactly one result.

SAMPLE OUTPUT

Please enter a phrase:

this is a test

1. Find the length of the string

2. Perform charAt

3. Perform equals

4. Perform compareTo

5. Perform indexOf

6. Perform substring

7. Perform toLowerCase

8. Perform toUpperCase

Please make a selection:

1

The length of the phrase is 14

Please enter a phrase:

this is a test

1. Find the length of the string

2. Perform charAt

3. Perform equals

4. Perform compareTo

5. Perform indexOf

6. Perform substring

7. Perform toLowerCase

8. Perform toUpperCase

Please make a selection:

2

Enter a number between 0 and 13:

8

The character at index 8 is 'a'

==========

Please enter a phrase:

this is a test

1. Find the length of the string

2. Perform charAt

3. Perform equals

4. Perform compareTo

5. Perform indexOf

6. Perform substring

7. Perform toLowerCase

8. Perform toUpperCase

Please make a selection

==========

Please enter a phrase:

this is a test

1. Find the length of the string

2. Perform charAt

3. Perform equals

4. Perform compareTo

5. Perform indexOf

6. Perform substring

7. Perform toLowerCase

8. Perform toUpperCase

Please make a selection:

4

Enter a phrase that will be compared with "this is a test":

this is a test

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago