Question

CSC110

Lab 6 (ALL CODING IN JAVA)

Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to the file:

  • Total number of words read

  • Total number of unique words read

  • Total number of sentences read

  • Total number of syllables read

  • Grade level – using Flesch readability index

YOU WILL NEED TO WRITE THE COMPLETE:

  • WordProcessor tester program
  • WordProcessor application program

Lab 6 CSC110 Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUE words and

equals o compares the word in a WordType object with the given String. If they are the same, the method will returm true, oth

getUniqueWords returns the number of unique words in the paragraph getTotWords returns the total number of words in the parag

WordApp You will need to prompt the user for the name of the input and output text files. If the input file does not exist, t

WORD TYPE:

/***************************************

/* Name:

/* Date:

/*

/* WordType Class for lab #6

***************************************/

public class WordType implements Comparable {

// instance data

private String word;

private int count;

private int syllables;

// Constructors

public WordType(String newWord) {

// initialize all data members - call private countSyllables() method

}

public WordType(WordType oldWord) {

// initialize all data members to match oldWord object

}

// Other methods

public void incCount() {

}

public String getWord() {

}

public int getCount() {

}

public int getSyllables() {

}

private boolean isVowel(char letter) {

}

private int countSyllables() {

int sylcount = 0;

boolean cluster = false; // clustering vowels

together into one syllable

for (int i = 0; i < word.length(); i++) {

if (isVowel(word.charAt(i)) == true) {

if (cluster == false) {

sylcount++;

cluster = true;

}

}

else {

cluster = false;

}

}

// Check for silent 'e' at end of the word

if (!isVowel(word.charAt(word.length()-2)) &&

word.charAt(word.length()-1) == 'e') if (word.length() > 1 && !isVowel(... *not sure if correct, had to add*
{

sylcount--;

}

if (sylcount < 1) {

sylcount = 1;

}

return sylcount;

}

public boolean equals(String other) {

}

public int compareTo(Object other) {

}

public String toString() {

}

}

WORD PROCESSOR:

/***************************************

/* Name:

/* Date:

/*

/* WordType Class for lab #6

***************************************/

import java.util.ArrayList;

import java.util.Collections;

public class WordProcessor {

private ArrayList<WordType> words;

private int numWords;

private int totSentences;

// the default constructor will create the ArrayList and initialize

the other variables to 0.

public WordProcessor() {

}

// A private boolean returning method. This method will be used by

addWord( ) before

// addWord actually adds a new word into the array.

private boolean isUnique(String newWord) {

}

// returns the index of the given WordType. If the word does not exist,

a -1 is returned.

private int indexOf(String other) {

}

// Adds the new word to the ArrayList of words. addWord() should remove

any terminating

// punctuation (periods, commas, exclamation points, question marks,

colons, semi-colons)

// from the words and make the word all lowercase before creating the

word object to be stored

// in the ArrayList Only UNIQUE words should be added to the list.

public void addWord(String newWord) {

// Remove terminating characters from the word => .,!?:;

// if removing ,!? increment sentences variable

// Make the word lower case before adding into the arraylist

// Check for uniqueness and then...

// ...increment count OR add the word to the array...

// ...based on the outcome

}

// returns the contents of the ArrayList as a formatted string

public String toString() {

}

// returns the number of unique words in the paragraph

public int getUniqueWords() {

}

public int getTotWords() {

}

public int getTotSentences() {

}

// Uses the static sort method from the Collections class

public void sort() {

Collections.sort(words);

}

// returns the total number of syllables of all the words stored in the

array. This will be used to

// calculate the readability index.

private int getNumSyllables() {

}

// returns the grade level of the text as a String.

// Calculate the index with the following formula:

// index = 206.835 - 84.6( numSyllables / numWords) - 1.015(

numWords / numSentences )

// use floating point arithmetic in all calculations

// round the result to the nearest integer (check Math.round() )

// Translated into educational levels, the index refers to:

// index level

// 91-100 5th grade

// 81-90 6th grade

// 71-80 7th grade

// 66-70 8th grade

// 61-65 9th grade

// 51-60 High school

// 31-50 College

// 0-30 College graduate

// < 0 Law School graduate

public String calcReadability() {

}

WORD TYPE TESTER:

/*********************************************************************\

This program will test the WordType class.

*********************************************************************/

public class WordTester

{

public static void main( String[] args )

{

//create object

WordType w = new WordType( "doggie" ); //

parameterized constructor

WordType y = new WordType( "house" );

WordType z = new WordType(x); // copy

constructor

System.out.println(x); // calling toString() & checking

syllables and count variables

w = new WordType( "cake" );

System.out.println(w); // calling toString() & checking

syllables and count variables

w = new WordType( "queue" );

System.out.println(w); // calling toString() & checking

syllables and count variables

// test all methods

System.out.println("getWord(): " + w.getWord());

System.out.println("getCount(): " + w.getCount());

w.incCount();

System.out.println("getCount() after increment: " +

w.getCount());

System.out.println("getSyllables(): " +

w.getSyllables());

System.out.println("obj == 'cat': " + w.equals("cat"));

System.out.println("obj == 'queue': "

+w.equals("queue"));

System.out.println("compareTo(w): " + w.compareTo(w));

System.out.println("compareTo(y): " + w.compareTo(y));

System.out.println("compareTo(z): " + w.compareTo(z));

System.out.println();

}

}

Lab 6 CSC110 Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUE words and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to the file Total number of words read Total number of unique words read Total number of sentences read Total number of syllables read Grade level using Flesch readability index WordType-used to store the words from the paragraph WordType -word String -count: int -syllables int +WordType(newwordString +WordType(oldword: WordType tincCount void +getWord String +getCount : int +getSyllablesint -isVowel(letter chaboolean tequals(other String : boolean +compareTo(otherWordTypeint +toString): String A word is any sequence of characters delimited by white space, whether or not it is an actual English word constructors o Counting syllables in a word. Use the following rules Each group of adjacent vowel (a, e, i, o, u, y) counts as one syllable However, an "e" at the end of a word doesn't count as a syllable Each word must have at least one syllable, even if the previous rules give a count of 0 The count data member should be initialized to 1-since this will be the first occurrence of the word o incCount * getWord . getCount o adds one to the count o returns the word stored in the object o returns how many times the word has occurred o returns how many syllables in the word o a private method used to determine if a character is a vowel. This will be useful when getSylables isVowel counting syllables
equals o compares the word in a WordType object with the given String. If they are the same, the method will returm true, otherwise the method will return false * compare lo o compares two WordType objects by comparing the words in the objects toString o retuns a String containing the word, the count and the number of syllables WordProcessor -words : ArrayList -totSentences int +WordProcessor () -isUnique (newword: Stringboolean -indexOf otherStringint +addWord( newWordStringvoid +getUniqueWords int +get TotWords) : int +getTotSentences): int +sort( void +get NumSyllables: int +calcReadability(): String tostring(): String default constructor the default constructor will create the ArrayList and initialize the other variables to 0 isUnique a private boolean returning method. This method will be used by addWord() before addWord actually adds a new word into the array indexOf returns the index of the given WordType. If the word does not exist, a -1 is returned addWord adds the new word to the ArrayList of words. addWord) should remove any terminating punctuation (periods, commas, exclamation points, question marks, colons, semi-colons) from the words and make the word all lowercase before creating the word object to be stored in the ArrayList Only UNIQUE words should be added to the list.
getUniqueWords returns the number of unique words in the paragraph getTotWords returns the total number of words in the paragraph getTotSentences returns the total number of sentences in the paragraph e Sort Uses the static sort method from the Collections class. More information can be found here getNumSyllables returns the total number of syllables of all the words stored in the array. This will be used to calculate the readability index. calcReadability returns the grade level of the text as a String. Calculate the index with the following formula numSyllables_ -1.015 numWords index 206.835-84.6 numWords numSentences use floating point arithmetic in all calculations o o round the result to the nearest integer (check Math.rounda) Translated into educational levels, the index refers to index 91-100 81-90 71-80 66-70 61-65 51-60 31-50 0-30 level 5th grade 6th grade 7th grade 8th grade 9th grade High school College College graduate Law School graduate toString returns the contents of the ArrayList as a formatted string
WordApp You will need to prompt the user for the name of the input and output text files. If the input file does not exist, throw an exception that will display an error message and loop back to the prompt. .Close the input file when you have completed reading and close the output file when you have completed writing. Output to the screen identification of the different steps happening during the processing. As there is no other output to the screen, this is helpful in identifying the progress of the program. For example, Counting words... Sorting words... Writing words to file... Writing statistics to file... Paragraph complete. Ask the user for another file to process until the user wants to quit. Break the application into meaningful methods that are short and perform only one function. Label the output clearly. You can design your own output format. Grading Rubric: working Word class with Test Driver working working Application $30 pts 25 pts 120 pts Total 75 pts WordProcessor class with Test Driver
0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA CODE:

import java.util.Scanner;

public class Alphabetical_Order

{

    public static void main(String[] args)

    {

        int n;

        String temp;

        Scanner s = new Scanner(System.in);

        System.out.print("Enter number of names you want to enter:");

        n = s.nextInt();

        String names[] = new String[n];

        Scanner s1 = new Scanner(System.in);

        System.out.println("Enter all the names:");

        for(int i = 0; i < n; i++)

        {

            names[i] = s1.nextLine();

        }

        for (int i = 0; i < n; i++)

        {

            for (int j = i + 1; j < n; j++)

            {

                if (names[i].compareTo(names[j])>0)

                {

                    temp = names[i];

                    names[i] = names[j];

                    names[j] = temp;

                }

            }

        }

        System.out.print("Names in Sorted Order:");

        for (int i = 0; i < n - 1; i++)

        {

            System.out.print(names[i] + ",");

        }

        System.out.print(names[n - 1]);

    }

}

// Java program to sort a string alphabetically

  

import java.util.Arrays;

  

public class GFG

{

    // Method to sort a string alphabetically

    public static String sortString(String inputString)

    {

        // convert input string to char array

        char tempArray[] = inputString.toCharArray();

          

        // sort tempArray

        Arrays.sort(tempArray);

          

        // return new sorted string

        return new String(tempArray);

    }

      

    // Driver method

    public static void main(String[] args)

    {

        String inputString = "tejavath";

        String outputString = sortString(inputString);

          

        System.out.println("Input String : " + inputString);

        System.out.println("Output String : " + outputString);

    }

}

import java.util.Arrays;

import java.util.Comparator;

  

public class GFG

{

    // Method to sort a mixed string

    public static String sortString(String inputString)

    {

        // convert input string to Character array

        Character tempArray[] = new Character[inputString.length()];

        for (int i = 0; i < inputString.length(); i++) {

            tempArray[i] = inputString.charAt(i);

        }

          

          

        // Sort, ignoring case during sorting

        Arrays.sort(tempArray, new Comparator<Character>(){

  

            @Override

            public int compare(Character c1, Character c2)

            {

                // ignoring case

                return Character.compare(Character.toLowerCase(c1),

                                        Character.toLowerCase(c2));

            }

        });

          

        // using StringBuilder to convert Character array to String

        StringBuilder sb = new StringBuilder(tempArray.length);

        for (Character c : tempArray)

            sb.append(c.charValue());

  

        return sb.toString();

    }

Add a comment
Know the answer?
Add Answer to:
CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the diagram below and the starter code, write Document Processor that will read a file...

    Using the diagram below and the starter code, write Document Processor that will read a file and let the user determine how many words of a certain length there are and get a count of all of the word lengths in the file. Your program should do the following: The constructor should accept the filename to read (word.txt) and then fill the words ArrayList up with the words from the file. The countWords method should accept an integer that represents...

  • Dictionary.java DictionaryInterface.java Spell.java SpellCheck.java In this lab you will write a spell check program. The program...

    Dictionary.java DictionaryInterface.java Spell.java SpellCheck.java In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the input file to be spell checked. The program will read in the words for the dictionary, then will read the input file and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is, add...

  • I've previously completed a Java assignment where I wrote a program that reads a given text...

    I've previously completed a Java assignment where I wrote a program that reads a given text file and creates an index that stores the line numbers for where individual words occur. I've been given a new assignment where I need to modify some of my old code. I need to replace the indexer in my Index class with a NavigableMap<String, Word> and update my Word class with NavigableSet<Integer> lines. The instantiated objects should be TreeMap() and TreeSet(). I have below...

  • JAVA Write a program which will read a text file into an ArrayList of Strings. Note...

    JAVA Write a program which will read a text file into an ArrayList of Strings. Note that the given data file (i.e., “sortedStrings.txt”) contains the words already sorted for your convenience. • Read a search key word (i.e., string) from the keyboard and use sequential and binary searches to check to see if the string is present as the instance of ArraryList. • Refer to “SearchInt.java” (given in “SearchString.zip”) and the following UML diagram for the details of required program...

  • Lab Description Sort all words by comparing the length of each word. The word with the...

    Lab Description Sort all words by comparing the length of each word. The word with the smallest length would come first. If you have more than one word with the same length, that group would be sorted alphabetically Input: The data file contains a list of words. The first line in the data file is an integer that represents the number of data sets to follow Output: Output the complete list of words in order by length. Sample Data 10...

  • Assignment 3: Word Frequencies Prepare a text file that contains text to analyze. It could be...

    Assignment 3: Word Frequencies Prepare a text file that contains text to analyze. It could be song lyrics to your favorite song. With your code, you’ll read from the text file and capture the data into a data structure. Using a data structure, write the code to count the appearance of each unique word in the lyrics. Print out a word frequency list. Example of the word frequency list: 100: frog 94: dog 43: cog 20: bog Advice: You can...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT