Write the following program in Java:




Entry.java:
package thesaurus;
class Entry
{
private static final int MAX_SYNONYMS = 10;
private String word;
private String[] synonyms;
private int synCount;
Entry(String word)
{
this.word = word;
this.synonyms = new String[MAX_SYNONYMS];
synCount = 0;
}
public String getWord()
{
return this.word;
}
public boolean addSynonym(String syn)
{
if(synCount < synonyms.length)
{
for(int i=0; i<synCount; i++)
{
if(isSynonym(syn)) return false;
}
synonyms[synCount++] = syn;
return true;
}
return false;
}
public String getSynonyms()
{
StringBuilder sb = new StringBuilder();
for(int i=0; i<synCount-1; i++)
{
sb.append(synonyms[i] + ", ");
}
sb.append(synonyms[synCount-1]);
return sb.toString();
}
public boolean isSynonym(String syn)
{
for(int i=0; i<synCount; i++)
{
if(synonyms[i].equalsIgnoreCase(syn)) return true;
}
return false;
}
}
Thesaurus.java:
package thesaurus;
class Thesaurus
{
private static final int MAX_ENTRIES = 7000;
Entry[] entries;
int entryCount;
Thesaurus()
{
entries = new Entry[MAX_ENTRIES];
entryCount = 0;
}
public Entry getEntry(String word)
{
for(int i=0; i<entryCount; i++)
{
if(entries[i].getWord().equalsIgnoreCase(word))
return entries[i];
}
return null;
}
public boolean addEntry(String word, String syn)
{
Entry entry = getEntry(word);
if(entry == null && entryCount < entries.length)
{
entry = new Entry(word);
entry.addSynonym(syn);
entries[entryCount++] = entry;
return true;
}
else if(entry != null)
{
return entry.addSynonym(syn);
}
else return false;
}
public String lookup(String word)
{
Entry entry = getEntry(word);
if(entry != null)
{
return entry.getSynonyms();
}
return word + " not found";
}
}
Proj6.java:
package thesaurus;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class Proj6
{
public static void main(String[] args) throws FileNotFoundException
{
Thesaurus thesaurus = new Thesaurus();
Scanner inputFile = new Scanner(new File("thesaurus.txt"));
while(inputFile.hasNextLine())
{
// take the 1st word in the line as word.
String word = inputFile.next();
// read rest of the string of the line.
// then split it based on whitespace delimiter.
String[] syns = inputFile.nextLine().split(" ");
// for each of the synonym
for(String syn : syns)
{
// add the word and synonym to the thesaurus.
if(!thesaurus.addEntry(word, syn))
{
System.out.println("Error adding synonym " + syn + " for the word " + word);
}
}
}
inputFile.close();
Scanner in = new Scanner(System.in);
while(true)
{
System.out.print("Enter (l)ookup, (a)dd entry, or (quit): ");
String userSelection = in.nextLine().toLowerCase();
switch(userSelection)
{
case "l":
System.out.print("Enter word: ");
Entry e = thesaurus.getEntry(in.nextLine());
System.out.println("Result: " + e.getSynonyms());
break;
case "a":
System.out.print("Enter word:");
String word = in.nextLine();
System.out.print("Enter synonym: ");
String syn = in.nextLine();
if(!thesaurus.addEntry(word, syn))
System.out.println("Error: Can't add entry");
break;
case "q": in.close(); return;
}
}
}
}
SAMPLE OUTPUT:
![Problems @Javadoc [B Declaration Console X P <terminated> Proj6 [Java Application] /usr/lib/jvm/java-11-ope Error adding synonym for the word word Enter (1)ookup, (a)dd entry, or (quit): ї Enter word: wordl Result:, synl, syn2, syn3 Enter (ookup, (a)dd entry, or (quit): a Enter word:wordl Enter synonym: syn99 Enter (1)ookup, (a)dd entry, or (quit): ї Enter word: wordl Result: , synl, syn2, syn3, syn99 Enter (ookup, (a)dd entry, or (quit):q](http://img.homeworklib.com/questions/18ddc680-6f0b-11eb-9d58-53f9a52b99b3.png?x-oss-process=image/resize,w_560)
Write the following program in Java: You are to write a Java program that reads an...
CÖ) Could you please help me to solve this problem?(ONLY USING C++ PROGRAMMING LANGUAGE PLEASE) Write a program for the patient information system in a policlinic. The patients are examined according to the triage char assigned to them. Triage codes are as follows: - ‘h’ : high priority - ‘m’ : medium priority - ‘l’ : low priority The patients having ‘h’ triage char are examined first then the patients having ‘m’ comes and finally patients with ‘l’ triage code...
This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by: player’s name player’s high score In your class, include: instance data variables two constructors getters and setters include appropriate value checks when applicable a toString method Part 2: PlayersList Class Write a class that manages a list...
Write a java program for the following: Your program reads an infix expression represented by a string S from the standard input (the keyboard). Then your program converts the infix expression into a postfix expression P using the algorithm. Next, your program evaluates the postfix expression P to produce a single result R. At last, your program displays the original infix expression S, the corresponding postfix expression P and the final result R on the standard output ( the screen...
Write a Java Program that reads the following:
Ask the user for a balance. From the
accounts.dat file, display all the accounts that
have a balance of at least what the user entered.
accounts.dat is a binary file. Each entry
contains a credit card number (long), a balance (double), and a
cash back flag (boolean).
Question 1 10 points Ask the user for a balance. From the accounts.dat file.display all the accounts that have a balance of at least what...
Today you are to write a Java program that will prompt for and
read 2 words of equal length entered by the user, and create a new
word which contains the last letter of the 1st word, the last
letter of the 2nd word, followed by the second to last character of
the 1st word, followed by the second to last character of the 2nd
word and so on. Be sure to use the same format and wording as in...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
Cipher Program Specifications: You are to write a program called, "Cipher123" that reads in an encoded message using the 1-2-3 cipher and returns the decoded message. The program should continue prompting for additional encoded messages until the user chooses to quit the program. When decoding a message, we take the first letter of the first word, the second letter of the second word and the third letter of the third word and concatenate them. We repeat this same process 1-2-3...
Write a program in Java according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "print" - prints the student records (first name, last name, grade). "sortfirst" - sorts the student records by first name. "sortlast" - sorts the student records by last name. "sortgrade" - sorts the...
Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...
You are to write a JAVA GUI that holds a dictionary. The GUI
should have a JList which contains all the words contained in the
dictionary. When a word is selected, you are to display the
corresponding definition (or synonym) in a text field (or text
area). When the user clicks the “Redefine” button, you should
prompt the user to enter a new definition with a pop-up window.
This should not only update the data in the GUI but also...