Question: Java Problem Statement You are asked to write a program which will prompt the user for a string in a specific format (see below). You

Java

Problem Statement

You are asked to write a program which will prompt the user for a string in a specific format (see below). You will then parse the input string and print it out a new message to the screen.

The string is expected to consist three parts separated by semicolon as follows:

; ;

The first and the second parts will be both integer. The third part will be a string. The first and second parts represent the indexes of the first and last character of a substring that your program will extract from the third part and print the answer to the console.

Here is an example:

1 ; 8 ; Java Programming ava Prog

Some Specifications

Your program must give an error message whenever one of these cases occur:

1. The user enters an empty string or only white spaces.

2. The user enters too many or too few semicolons. There should only be 2 allowed.

3. The first or second integer is negative.

4. The second integer is larger than the String length.

5. The first integer is larger than the second integer.

You will need to use Integer.parseInt(), so if your program crashes from using this that is ok. I would suggest using trim() before passing the integers to Integer.parseInt().

You will need to use indexOf and substring, but you are NOT allowed to use split(). Remember, there is an overloaded version of indexOf which may be useful.

Example

Java Problem Statement You are asked to write a program which will

8;26; send please 015 JohnOgoogle.comta -* JohnOgoogle.com -1 17; JohnOgoogle.comta >Invalid Index! 5; 2; JohnOgoogle.comta -> Invalid Index! 5 ; 50; John@google.comta- Invalid Index ! to office@hotmail. com office@hotmail. com

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!