Question: PLEASE WRITE JAVA CODES The program The program must be able to open any text file specified by the user, and analyze the frequency of
PLEASE WRITE JAVA CODES
The program
The program must be able to open any text file specified by the user, and analyze the frequency of verbal tics in the text. Since there are many different kinds of verbal tics (such as "`like`", "`uh`", "`um`", etc) the program must ask the user what tics to look for. A user can enter multiple tics, separated by commas - any spaces entered by the user before or after each tic must be ignored. You can assume all tics are single words.
The program should output:
- the total number of tics found in the text
- the density of tics (proportion of all words in the text that are tics)
- the frequency of each of the verbal tics
- the percentage that each tic represents out of all the total number of tics
## Example input and output
This example shows suggested input/output of such a program. User responses are shown with "`>`" in front of them for your convenience, although this character should not be output by the program or entered by the user. Data analysis numbers are placeholder only and are not meant to be '_real_'.
```
What file would you like to open?
> data/trump_speech_010621.txt
What words would you like to search for?
> uh,like, um,so
...............................Analyzing text.................................
Total number of tics: 66
Density of tics: 0.2
...............................Tic breakdown..................................
uh / 0 occurrences / 0% of all tics
like / 33 occurrences / 12% of all tics
um / 63 occurrences / 23% of all tics
so / 138 occurrences / 50% of all tics
```
## Requirements
- The program must be able to analyze any text file, but an example file must be included in the submission.
- The user must be able to enter as many tics as they would like, separated by commas, with or without spaces.
- Those tics can be assumed to be single words, such as "uh" and "like", and not multi-word tics such as "uh huh" and "you know".
- The list of tics entered by the user must be stored in an array, not an ArrayList or any other array-like data structure.
- You must use separate methods for each component of the analysis. At the least, this includes:
1. asking the user which text file to open.
1. opening the file and importing its contents.
1. soliciting tic words or phrases from the user and separating them into an array.
1. counting the occurrences of each tic.
1. calculating the percent of all tics that each tic consumes.
1. calculating tic density.
- The output must be formatted so that all output lines up nicely as in the example
- the tic word column consumes 10 spaces
- the number of occurrences column consumes 20 spaces
- the percentage column consumes as much space as necessary
- columns are separated by the `/` characters - note that the text within any column should always be separated one space away from this separator - see example output
- The search for tics must be case insensitive.
- round all occurrences and percentages to the nearest integer.
- limit the density to two decimal places.
## Helpful hints
You _may_ find it useful to split strings by more than one separator.
```java
String someText = "this;text,has-various?separators+in!it";
String[] values = someText.split("[.,?!-]+"); // an array of the parts of the String separated by any of the indicated separators
```
To make a string consume a fixed amount of space, use the `String.format()` function, e.g.:
```java
// format a string
String old = "hello";
String new = String.format("%10s", old); // returns "hello "
```
```java
// format an integer
int old = 6;
String new = String.format("%10d", old); // returns "6 "
```
```java
// format a floating point number
double old = 6.0;
String new = String.format("%10f", old); // returns "6.0 "
```
```java
// limit the number of decimal places in a floating point number
double old = 3.14159265; // pi!
String new = String.format("%.2f", old); // returns "3.14";
```
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
