Write a program IN JAVA to simulate a calculator for String values. The program should take three inputs from the user. The first two inputs are of type String. The user may enter any text. The third input is also a String but limited to one of these words – concat, contains, and equal. These words indicate operations that can be performed on the previous two strings. Example 1: if the user entered the following (bold text is user input): Enter String 1: Hello Enter String 2: World Enter String 3: Concat Your program should join/concatenate Hello and World to print “Hello World” Example 2: if the user entered the following (bold text is user input): Enter String 1: My name is Joe Enter String 2: Joe Enter String 3: Contains Your program should check if Joe is contained in My name is Joe and print the result of the operation with a helpful message, ““Joe” is contained in “My name is Joe”” Example 3: if the user entered the following Enter String 1: Hello Enter String 2: Hello Enter String 3: Equal Your program should check if Hello is equal to Hello and print the result of the operation with a helpful message “”Hello” is equal to “Hello”” Hint: Use a switch statement. The keywords concat, contains, and equal can be used as an input to the switch statement. Use methods from String
Write a
The first two inputs are of type String. The user may enter any text.
The third input is also a String but limited to one of these words – concat, contains, and equal. These words indicate operations that can be performed on the previous two strings.
Example 1: if the user entered the following (bold text is user input):
Enter String 1: Hello
Enter String 2: World
Enter String 3: Concat
Your program should join/concatenate Hello and World to print “Hello World”
Example 2: if the user entered the following (bold text is user input):
Enter String 1: My name is Joe
Enter String 2: Joe
Enter String 3: Contains
Your program should check if Joe is contained in My name is Joe and print the result of the operation with a helpful message, ““Joe” is contained in “My name is Joe””
Example 3: if the user entered the following
Enter String 1: Hello
Enter String 2: Hello
Enter String 3: Equal
Your program should check if Hello is equal to Hello and print the result of the operation with a helpful message “”Hello” is equal to “Hello””
Hint: Use a switch statement. The keywords concat, contains, and equal can be used as an input to the switch statement. Use methods from String.
Answer:
Step by step
Solved in 2 steps with 1 images