In Java, using Collections, Ask the user for Strings until he or she types exit. Display those String without duplicates in alphabetical order.
Please provide comments to get a better understanding.
//////////////////////////////////////////////////////////////////Required output\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Test Case 1
Standard Input |
---|
cENTER bENTER bENTER cENTER aENTER aENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n a\n b\n c\n
Test Case 2
Standard Input |
---|
bENTER cENTER aENTER aENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n a\n b\n c\n
Test Case 3
Standard Input |
---|
process improvementENTER strategyENTER VersatileENTER encodingENTER monitoringENTER ImplementedENTER encompassingENTER ProfoundENTER 4th generationENTER Grass-rootsENTER encodingENTER monitoringENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n 4th generation\n encoding\n encompassing\n Grass-roots\n Implemented\n monitoring\n process improvement\n Profound\n strategy\n Versatile\n
Test Case 4
Standard Input |
---|
FundamentalENTER executiveENTER intermediateENTER Customer-focusedENTER portalENTER ErgonomicENTER MandatoryENTER capacityENTER solutionENTER mission-criticalENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n capacity\n Customer-focused\n Ergonomic\n executive\n Fundamental\n intermediate\n Mandatory\n mission-critical\n portal\n solution\n
Test Case 5
Standard Input |
---|
pricing structureENTER web-enabledENTER mobileENTER middlewareENTER InnovativeENTER leverageENTER hubENTER explicitENTER asymmetricENTER time-frameENTER throughputENTER globalENTER fresh-thinkingENTER conceptENTER localENTER Triple-bufferedENTER firmwareENTER TotalENTER collaborationENTER challengeENTER AutomatedENTER encodingENTER UniversalENTER internet solutionENTER bottom-lineENTER Multi-lateralENTER actuatingENTER neutralENTER monitoringENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n actuating\n asymmetric\n Automated\n bottom-line\n challenge\n collaboration\n concept\n encoding\n explicit\n firmware\n fresh-thinking\n global\n hub\n Innovative\n internet solution\n leverage\n local\n middleware\n mobile\n monitoring\n Multi-lateral\n neutral\n pricing structure\n throughput\n time-frame\n Total\n Triple-buffered\n Universal\n web-enabled\n
Test Case 6
Standard Input |
---|
UniversalENTER internet solutionENTER bottom-lineENTER Multi-lateralENTER pricing structureENTER web-enabledENTER mobileENTER middlewareENTER InnovativeENTER leverageENTER hubENTER explicitENTER asymmetricENTER time-frameENTER throughputENTER globalENTER fresh-thinkingENTER conceptENTER localENTER Triple-bufferedENTER firmwareENTER TotalENTER collaborationENTER challengeENTER AutomatedENTER leverageENTER hubENTER explicitENTER asymmetricENTER time-frameENTER throughputENTER globalENTER fresh-thinkingENTER encodingENTER UniversalENTER internet solutionENTER bottom-lineENTER Multi-lateralENTER leverageENTER hubENTER explicitENTER asymmetricENTER time-frameENTER throughputENTER globalENTER fresh-thinkingENTER actuatingENTER neutralENTER monitoringENTER UniversalENTER internet solutionENTER bottom-lineENTER Multi-lateralENTER exit |
Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n Enter a line of text\n actuating\n asymmetric\n Automated\n bottom-line\n challenge\n collaboration\n concept\n encoding\n explicit\n firmware\n fresh-thinking\n global\n hub\n Innovative\n internet solution\n leverage\n local\n middleware\n mobile\n monitoring\n Multi-lateral\n neutral\n pricing structure\n throughput\n time-frame\n Total\n Triple-buffered\n Universal\n web-enabled\n
Given below is the code for the question. Please do rate the answer if it helped. Thank you.
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class UniqueWords {
public static void main(String[] args) {
Scanner in = new
Scanner(System.in);
String line;
boolean done = false;
TreeSet<String> set = new
TreeSet<String>(new Comparator<String>() {
@Override
public int
compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
}); //create a treeset which
compares string ignoring their case. Also treeset store unique
values and in sorted manner
while(!done){
System.out.println("Enter a line of text:");
line =
in.nextLine();
if(line.equalsIgnoreCase("exit"))
done = true;
else
set.add(line);
}
for(String s: set)
System.out.println(s);
}
}
output
----
Enter a line of text:
pricing structure
web-enabled
mobile
middleware
Innovative
leverage
hub
explicit
asymmetric
time-frame
throughput
global
fresh-thinking
concept
local
Triple-buffered
firmware
Total
collaboration
challenge
Automated
encoding
Universal
internet solution
bottom-line
Multi-lateral
actuating
neutral
monitoring
exitEnter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
Enter a line of text:
actuating
asymmetric
Automated
bottom-line
challenge
collaboration
concept
encoding
explicit
firmware
fresh-thinking
global
hub
Innovative
internet solution
leverage
local
middleware
mobile
monitoring
Multi-lateral
neutral
pricing structure
throughput
time-frame
Total
Triple-buffered
Universal
web-enabled
In Java, using Collections, Ask the user for Strings until he or she types exit. Display...
6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...
Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...