Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to create a program that generates a grammatically correct English sentences(more than 100) that gets its words from a txt file that contains

I need to create a program that generates a grammatically correct English sentences(more than 100) that gets its words from a txt file that contains all the words in the English Dictionary. Theses sentences should be no more than ten words long and they don't need to be overly complex just so long as they make some sort of sense. The code below is what we are given and will read said text file and pick out a word from a location in that file based on the number you give it. Once its done it should store the sentences in an array. Another note is that you are only able to use the basic java libraries. The code provided does not need to be used and the same goes for the txt file I described you can use your own version of it. I just need a simple way of generating these sentences there is no need for the code to be overly complex.

import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException;

class Dictionary{ private String input[];

public Dictionary(){ input = load("C:\\Users\\aking\\Downloads//words2.txt"); } public int getSize(){ return input.length; } public String getWord(int n){ return input[n]; } private String[] load(String file) { File aFile = new File(file); StringBuffer contents = new StringBuffer(); BufferedReader input = null; try { input = new BufferedReader( new FileReader(aFile) ); String line = null; int i = 0; while (( line = input.readLine()) != null){ contents.append(line); i++; contents.append(System.getProperty("line.separator")); } }catch (FileNotFoundException ex){ System.out.println("Can't find the file - are you sure the file is in this location: "+file); ex.printStackTrace(); }catch (IOException ex){ System.out.println("Input output exception while processing file"); ex.printStackTrace(); }finally{ try { if (input!= null) { input.close(); } }catch (IOException ex){ System.out.println("Input output exception while processing file"); ex.printStackTrace(); } } String[] array = contents.toString().split(" "); for(String s: array){ s.trim(); } return array; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago