This project performs text analysis using StringBuffer
in Java. It counts how many sentences in a given text contain each word from a provided array of words. The program reads the text and words from user input, processes the text, and outputs the results.
Determine C3 as the remainder of dividing the student's record book number 13879064 by 3, and C17 as the remainder of dividing the student's record book number 13879064 by 17.
Based on C3, determine the type of text variables:
C3 | Type |
---|---|
2 | StringBuffer |
Based on C17, determine the text operation:
C17 | Operation |
---|---|
9 | Given a text and an array of words, count in how many sentences each word from the array appears. |
Variant:
- C3 = 2: Use
StringBuffer
for text variables. - C17 = 9: Given a text and an array of words, count how many sentences contain each word from the array.
- Text Input: Users can input any text they wish to analyze.
- Word List Input: Users can specify a list of words to search for within the text.
- Sentence Parsing: The text is split into sentences based on punctuation marks (., !, ?).
- Word Counting: Counts the number of sentences in which each word appears.
- Exception Handling: Robust error handling for invalid inputs and null values.
- Uses StringBuffer: All string manipulations are performed using
StringBuffer
, as per the assignment requirements. - Code Standards: Adheres to Java Code Conventions (or Google Java Style Guide).
- Java Development Kit (JDK) 8 or higher installed on your system.
- Git (optional, for cloning the repository).
If the project is hosted on GitHub, clone it using:
git clone https://github.com/HlibPavlyk/text-analyzer.git
cd text-analyzer/src
Alternatively, you can download the source code files directly.
Open a terminal or command prompt in the project directory and compile the Java files:
javac Main.java TextUtils.java
After successful compilation, run the program using:
java Main
-
Starting the Program:
- Run
java Main
in your terminal.
- Run
-
Input Text:
- The program will prompt:
Enter the text:
- Input the text you want to analyze. This can be multiple sentences ending with periods, exclamation marks, or question marks.
- The program will prompt:
-
Input Word List:
- The program will prompt:
Enter the number of words to search:
- Input an integer representing how many words you want to search for.
- For each word, you will be prompted:
Enter word X:
- Input each word you want to search for in the text.
- The program will prompt:
-
Results Display:
- After processing, the program will display how many sentences contain each word:
Word 'example' occurs in 2 sentences. Word 'test' occurs in 1 sentences.
- After processing, the program will display how many sentences contain each word:
Enter the text:
This is a test. Testing is essential! Is this example sufficient? Yes, this example should suffice.
Enter the number of words to search:
2
Enter word 1:
test
Enter word 2:
example
Word 'test' occurs in 1 sentences.
Word 'example' occurs in 2 sentences.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to reach out for any questions or suggestions regarding this project.