Need a itte help. Requirements: 1. We are going to write a console based word pr
ID: 3766603 • Letter: N
Question
Need a itte help.
Requirements:
1. We are going to write a console based word processor in this assignment.
2. First of all the user should type some paragraph or sentence. Therefore the user should be asked to enter some text. (“Please enter some sentence or paragraph.”).
3. After the program accepts the text, the user should be taken to the main menu of the program, which consists of several operations that the user can ask the program to perform.
4. The user should be able to: 4.1. Convert paragraph to all caps. 4.2. Convert paragraph to lowercase. 4.3. Delete whitespaces. 4.4. Split words and Remove duplicates 4.5. Search a certain word.
5. When the 4th choice (“Split Words”) is selected, the words should be put into an array or a structure of your preference and each word should be displayed with a loop. After this duplicate removal should be performed and the program must determine the duplicate words and eliminate them. After this, the word list should be printed again.
6. 5th choice is a straightforward one. If the searched word is found within the text then the program must indicate that it is found. If the word is not there then it should warn the user and say : “The word : “someWord” could not be found
Explanation / Answer
Hi,
Below is the program that you are looking for:
Program:
package java_project;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
class CaseChange{
public static void main(String args[])
{
int switchvalue;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an input String: ");
String inputString = scanner.nextLine();
// Display menu graphics
System.out.println("============================");
System.out.println("| STRING MENU SELECTION |");
System.out.println("============================");
System.out.println("| Options: |");
System.out.println("| 1. Option 1 to uppercase |");
System.out.println("| 2. Option 2 to lowercase |");
System.out.println("| 3. Option 3 to Delete whitespaces |");
System.out.println("| 4. Option 4 to Splitwords and remove duplicates |");
System.out.println("| 5. Option 5 search a word |");
System.out.println("============================");
System.out.println("Please enter your choice ");
Scanner d=new Scanner(System.in);
switchvalue=d.nextInt();
// Switch construct
switch (switchvalue) {
case 0:
System.out.println("Option 1 to convert the sentence to uppercase ");
toUppercase(inputString);
break;
case 1:
System.out.println("Option 2 to convert to lower case ");
toLowercase(inputString);
break;
case 3:
System.out.println("Option 3 to delete whitespaces ");
toDeletewhitespaces(inputString);
break;
case 4:
System.out.println("Option 4 to split words and remove duplicates ");
toRemoveduplicates(inputString);
case 5:
System.out.println("Option 5 to search a word ");
toSearchword(inputString);
default:
System.out.println("Invalid selection");
break;
}
}
public static String toUppercase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToUpperCase = Character.toUpperCase(currentChar);
result = result + currentCharToUpperCase;
}
return result;
}
public static String toLowercase(String inputString) {
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharToLowerCase = Character.toLowerCase(currentChar);
result = result + currentCharToLowerCase;
}
return result;
}
public static String toDeletewhitespaces(String inputString){
String result = "";
String replaceStr = " ";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
char currentCharTodeletespaces = currentChar.replaceAll("\s", "");
result = result + currentCharTodeletespaces ;
}
return result;
}
public static String toRemoveduplicates(String inputString){
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
List<String> list = Arrays.asList(currentChar.split(" "));
Set<String> uniqueWords = new HashSet<String>(list);
for (String word : uniqueWords) {
System.out.println(word + ": " + Collections.frequency(list, word));
result=result+list;
}
}
return result;
}
public static String toSearchword(String inputString){
String result = "";
for (int i = 0; i < inputString.length(); i++) {
char currentChar = inputString.charAt(i);
int intIndex = currentChar.indexOf("value");
if(intIndex == - 1){
System.out.println("value not found");
}else{
System.out.println("Found Hello at index "
+ intIndex);
}
}
}
Hope that helps...HAPPY ANSWERING!!!!!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.