Question
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
|
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started