Question

In: Computer Science

A client at a software design company wants assistance processing their documents. After interviewing the client...

A client at a software design company wants assistance processing
their documents.  After interviewing the client you find that their
documents consist of a one sentence title, a date, and a series of
paragraphs.  Each paragraph is a simple list of sentences.  Paragraphs
are separated by new lines.  Each document also has an author (first
and last name) and a document access level (open, internal or
confidential).

 At a minimal level the client would like the software to be able to:
* Count the number of words in the document (with or without the
  title)
* Count the number of characters in the document
* Print out a document
* Print out the date of the document
* Print out the author of the document

Additional desirable features:
* Count the number of a particular type of word (noun, verb, proper
  noun or other) 
* Given a title, date, author and a string for the remaining document,
  create a document file
* Spell check the document 

Solutions

Expert Solution

JAVA Code :

import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
import java.io.FileWriter;   // Import the FileWriter class
import java.io.IOException; // Import the IOException class to handle errors

public class Main {
    public static void main(String[] args) {
        int ch = 0;
        Scanner sc= new Scanner(System.in);    //System.in is a standard input stream

        while(ch!=3){
            System.out.println("Menu : ");
            System.out.println("1. Read a File.");
            System.out.println("2. Write to a File.");
            System.out.println("3. Exit.");
          
            ch = sc.nextInt();
          
            switch (ch) {
                case 1 :
                    try {
                        File doc1 = new File("Document1.txt"); //Create File Object to read file "Document1.txt"
                        Scanner doc1Reader = new Scanner(doc1);
                        String title="", date="", author="", accessLevel="", data = "";
                        String[] paragraph;
                        int numOfWordsWithTitle = 0, numOfWordsWithoutTitle = 0, numOfCharactersWithTitle = 0, numOfCharactersWithoutTitle = 0;
                      
                        title = doc1Reader.nextLine(); //Read Title from Document1.txt
                        date = doc1Reader.nextLine(); //Read Date from Document1.txt
                        author = doc1Reader.nextLine(); //Read Author from Document1.txt
                        accessLevel = doc1Reader.nextLine(); //Read Access Level from Document1.txt
              
                        while (doc1Reader.hasNextLine()) {
                        data = data + doc1Reader.nextLine(); //Read Data from Document1.txt
                        }
              
                        numOfCharactersWithTitle = title.length() + data.length(); //Calculate Number of Characters with title.
                        numOfCharactersWithoutTitle = data.length(); //Calculate Number of Characters without title.
                      
                        numOfWordsWithTitle = title.split(" ", 100).length;
                        numOfWordsWithoutTitle = 0;
                        paragraph = data.split("\n", 100);
                  
                        for(int i = 0; i < paragraph.length; i++){
                            numOfWordsWithTitle = numOfWordsWithTitle + paragraph[i].split(" ", 1000).length; //Calculate Number of Words with title.
                            numOfWordsWithoutTitle = numOfWordsWithoutTitle + paragraph[i].split(" ", 1000).length; //Calculate Number of Words without title.
                        }
                  
                        System.out.println("Document Data : ");
                        System.out.println(data); //Display Data.
                        System.out.println("Document Date : ");
                        System.out.println(date); //Display Date.
                        System.out.println("Document Author : ");
                        System.out.println(author); //Display Author.
                        System.out.println("Document Word count (with title) : ");
                        System.out.println(numOfWordsWithTitle); //Display Data Word count (with title).
                        System.out.println("Document Word count (without title) : ");
                        System.out.println(numOfWordsWithoutTitle); //Display Data Word count (without title).
                        System.out.println("Document Character count (with title) : ");
                        System.out.println(numOfCharactersWithTitle); //Display Data Character count (with title).
                        System.out.println("Document Character count (without title) : ");
                        System.out.println(numOfCharactersWithoutTitle); //Display Data Character count (without title).
                        System.out.println("Document Title : ");
                        System.out.println(title); //Display Title.
                        System.out.println("Document Access Level : ");
                        System.out.println(accessLevel); //Display Access Level.
                      
                        doc1Reader.close();
                    } catch (FileNotFoundException e) {
                        System.out.println("An error occurred.");
                        e.printStackTrace();
                    }
                    break;
                  
                case 2 :
                    try {
                        FileWriter doc2Writer = new FileWriter("Document2.txt");
                        String title, date, author, accessLevel, data = "";
                      
                        sc.nextLine();
                        System.out.println("Enter Title : ");
                        title = sc.nextLine(); //Get Title from User.
                        System.out.println("Enter Date : ");
                        date = sc.nextLine(); //Get Date from User.
                        System.out.println("Enter Author Name (FirstName LastName) : ");
                        author = sc.nextLine(); //Get Author from User.
                        System.out.println("Enter Access Level (Open/Internal/Confidential) : ");
                        accessLevel = sc.nextLine();
                        System.out.println("Enter Data : ");
                        data = sc.nextLine();
                      
                        //Write to File.
              
                        doc2Writer.write(title + "\n");
                        doc2Writer.write(date + "\n");
                        doc2Writer.write(author + "\n");
                        doc2Writer.write(accessLevel + "\n");
                        doc2Writer.write(data + "");
                      
                        doc2Writer.close();
                        System.out.println("Successfully wrote to the file.");
                    } catch (IOException e) {
                        System.out.println("An error occurred.");
                        e.printStackTrace();
                    }
                break;
            }
        }
    }
}

Screenshots :

Code :

Document 1 :

Document 2 :

OutPut :


Related Solutions

A financial planner wants to design a portfolio of investments for a client. The client has...
A financial planner wants to design a portfolio of investments for a client. The client has $300,000 to invest and the planner has identified four investment options for the money. The following requirements have been placed on the planner. No more than 25% of the money in any one investment, at least one third should be invested in long-term bonds which mature in seven or more years, and no more than 25% of the total money should be invested in...
Design the logic in pseudocode for Bugz App software company that sells a software package as...
Design the logic in pseudocode for Bugz App software company that sells a software package as follows. 1. The retail price of the package is $99 2. Quantity discounts are given on purchases of 10 or more units as follows The program must allow the user to enter the customer’s name and number of units purchased, and output the original cost of the units purchased, the percentage discount given, the dollar amount of the discount given, and the final cost...
Your software development company wants to continue developing and enhancing a software application for internal use....
Your software development company wants to continue developing and enhancing a software application for internal use. For this week's assignment, the application is required to read from a file (data.txt) containing employee data. Your tasks include: Use the data file from Week One (data.txt) Implement LINQ functionalities to search, display, and modify employees' records Meet specifications by displaying on a Windows Form Application Program Input File: Using Visual Studio and C# programming concepts and using your Week one data.txt file...
An experienced Python programmer in your company wants your assistance calculating the division of the numerator...
An experienced Python programmer in your company wants your assistance calculating the division of the numerator being the sum of all the multipliers of four divided by the denominator of all the multipliers of three using one for loop and one range statement respectively. Both sums of the numerator and denominator respectively are to be calculated using the same range of numbers between (and including) the number 0 and up to (and including) the number 100. The experienced Python programmer...
You are an IT company and want to get a daycare's network design, hardware, software, and...
You are an IT company and want to get a daycare's network design, hardware, software, and security. Project resources allocation. List all types of resources (e.g. human and non-human) you will use them in the enterprise network project. How are you planning to use those resources cost-effectively?
Software Design When is the model-view-controller pattern better than the client-server pattern? Why? Justify your answer.
Software Design When is the model-view-controller pattern better than the client-server pattern? Why? Justify your answer.
Newsoft is a computer software company that is setting up a new program design facility in...
Newsoft is a computer software company that is setting up a new program design facility in a nation that the company has not had any relationship with before. Yusuf is the Human Resource manager for the entire company. He is considering two different candidates to be the Operations manager of the new facility, Maria (who is a woman) and Raj (who is a man). Maria is better qualified than Raj for this new opportunity and is Jared’s preferred choice. Jared...
You are an IT company and want to get a travel agency's network design, hardware, software,...
You are an IT company and want to get a travel agency's network design, hardware, software, and security. DMZ Architecture: What is your DMZ architecture? What devices and their function are included? How are DMZ devices connected? How are you planning to provide security to protect the DMZ and at the same time maintaining friendly access to customers?
You are an IT company and want to get a travel agency's network design, hardware, software,...
You are an IT company and want to get a travel agency's network design, hardware, software, and security. Project resources allocation. List all types of resources (e.g. human and non-human) you will use them in the enterprise network project. How are you planning to use those resources cost-effectively?
You are an IT company and want to get a travel agency's network design, hardware, software,...
You are an IT company and want to get a travel agency's network design, hardware, software, and security. What’s the difference between IDS and Firewall? What is a promiscuous mode in IDS? What is an in-line mode in IDS? When is appropriate to use one or the other in your network? Specific to a travel agency what firewall & IDS vendors’ such as Palo Alto Networks, Check Point, Cisco, etc., and select product(s) suitable for the travel agency. Justify your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT