In: Computer Science
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings.
First, the program prompts: Please enter a string.
The program should read in the string, and prompts: Please enter another string.
The program reads in two strings and it prints a menu to the user.
The program asks for user to enter an option and performs one of the following:
Here are the options on the menu:
Option a: checks if the length of the two strings are the same.
Option b: checks if two strings are same or different.
Option c: checks which string is lexically larger, or if they are same
Option d: prints out the first character (index 0) of each string
Option e: prints out a new string consisting of the first string concatenated (appended) with the second string.
Option f: prints out two strings using upper case letters.
Option q: quit the program.
// Please find the required solution import java.util.Scanner; // Assignment class performs string operations with menu public class Assignment3 { public static void main(String[] args) { // instantiate scanner to read input from keyboard Scanner input = new Scanner(System.in); char option; // read string 1 System.out.println("Enter String:"); String s1 = input.nextLine(); // read string 1 System.out.println("Enter Another String:"); String s2 = input.nextLine(); // print menu as given in question System.out.println("-------Menu-------"); System.out.println("Option a: checks if the length of the two strings are the same"); System.out.println("Option b: checks if two strings are same or different"); System.out.println("Option c: checks which string is lexically larger, or if they are same"); System.out.println("Option d: prints out the first character (index 0) of each string"); System.out.println("Option e: prints out a new string consisting of the first string concatenated (appended) with the second string"); System.out.println("Option f: prints out two strings using upper case letters"); System.out.println("Option q: quit the program"); // perform above operations on string do { System.out.println("Enter the option:"); option = input.nextLine().charAt(0); switch (option) { case 'a': System.out.println("Two String Lengths are " + (s1.length() == s2.length() ? "same" : "different")); break; case 'b': System.out.println("Two strings are " + (s1.equals(s2) ? "same" : "different")); break; case 'c': int value = s1.compareTo(s2); if (value == 0) System.out.println("Two strings are Lexically same."); else if (value > 0) System.out.println(s1 + " is lexically larger"); else System.out.println(s2 + " is lexically larger"); break; case 'd': System.out.println("First characters :"); System.out.println(s1.charAt(0) + " " + s2.charAt(0)); break; case 'e': String newString = s1.concat(s2); System.out.println(newString); break; case 'f': System.out.println("Upper case of s1:" + s1.toUpperCase()); System.out.println("Upper case of s2:" + s2.toUpperCase()); break; case 'q': System.out.println("you have selected to quit:"); break; default: System.out.println("Invalid option Selected please try again"); } } while (option != 'q'); input.close(); } } sample screenshot: