Question

In: Computer Science

Question 13 We define the letters 'a', 'e', 'i', 'o' and 'u' as vowels. We do...

Question 13

We define the letters 'a', 'e', 'i', 'o' and 'u' as vowels. We do not consider any other letter as a vowel.

Write a function named initialVowels() that returns a list of words in a body of text that begin with a vowel.

Include both capitalized and lower case instances of the vowels.

A word should appear in the return list at most once, no matter how many times is occurs in the input string.

Input: a string that consists of words, separated by spaces

Return: an list of words in the input string that begin with an upper or lower case vowel

For example, the following would be correct output:

>>> mlk = 'Our lives begin to end the day we become silent about things that matter'

>>> print(initialVowels(mlk))

['Our','about']

Question 14

The three words 'a', 'an' and 'the' are the only articles in the English language.

Write a function named countArticles(). Hint: Count both capitalized and lower case instances of articles.

Input: a string, named sentence

Return: the number of words in sentence that are articles

For example, the following would be correct output:

>>> theFlea = ['The flea is a mighty insect']

>>> print(articleCount(theFlea))

>>> 2

Question 15

Write a function named pluralCount() that takes two string parameters.

The first parameter is the name of an input file that exists before pluralCount() is called.

The second parameter is the name of an output file that pluralCount() creates and writes to.

You may assume that the input file is in the current working directory and you should write the output file to that directory as well.

For each line in the input file, the function pluralCount() should write to the output file the number of words in the line that end in the letter 's'.

For example, if the following is the content of the file foxInSocks.txt:

Look, sir. Look, sir. Mr. Knox, sir.

Let's do tricks with bricks and blocks, sir.

Let's do tricks with chicks and clocks, sir.

The following function call:

inF = 'foxInSocks.txt'

outF = 'foxRepLines.txt'

pluralCount(inF, outF)

should create the file ‘foxRepLines.txt’ with the content:

0

4

4

Solutions

Expert Solution

This class is for PLural count

package accountProject;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Vowels{

   private static final String FILENAME= "C:\\Users\\cr\\Desktop\\input.txt";
   private static final String FILENAME1 = "C:\\Users\\cr\\Desktop\\output.txt";
  
   static ArrayList<Integer> countlist;
   public static ArrayList<Integer> countlist(File file){
       countlist=new ArrayList<Integer>();
       BufferedReader br = null;
       FileReader fr = null;
       FileWriter fw=null;
       BufferedWriter bw=null;
      
       try {

           fr = new FileReader(file);
           br = new BufferedReader(fr);
          
           String sCurrentLine;
          
           br = new BufferedReader(new FileReader(file));
                  
                                  
           while ((sCurrentLine = br.readLine()) != null) {
               int count=0;
               System.out.println(sCurrentLine);
               String wordl[]=sCurrentLine.split(" ");
               for(String word:wordl){
                  
                   if(word.replace(",", "").toLowerCase().endsWith("s")){
                       count++;
                      
                      
                   }
               }
               countlist.add(count);
           }
          
          


       } catch (IOException e) {

           e.printStackTrace();

       } finally {

           try {

               if (br != null)
                   br.close();

               if (fr != null)
                   fr.close();

           } catch (IOException ex) {

               ex.printStackTrace();

           }

       }
       System.out.println(countlist.toString());
       return countlist;

   }
  
   public static void WriteToFile(File file){
          
       BufferedWriter bw = null;
       FileWriter fw = null;

       try {

          

           // if file doesnt exists, then create it
           if (!file.exists()) {
               file.createNewFile();
           }

           // true = append file
           fw = new FileWriter(file.getAbsoluteFile(), true);
           bw = new BufferedWriter(fw);
           File input=new File(FILENAME);
           File output=new File(FILENAME1);
           ArrayList<Integer>list=Vowels.countlist(input);
          
           for(Integer i:list){
               bw.write(i.toString());
               bw.newLine();
           }

           System.out.println("Done");

       } catch (IOException e) {

           e.printStackTrace();

       } finally {

           try {

               if (bw != null)
                   bw.close();

               if (fw != null)
                   fw.close();

           } catch (IOException ex) {

               ex.printStackTrace();

           }
       }


          
      
           }

  
  
   public static void main(String[] args) {

       Vowels v=new Vowels();
       File file=new File(FILENAME);
       File file1=new File(FILENAME1);
       v.countlist(file);
       v.WriteToFile(file1);

   }
  
}

THis is main class

package accountProject;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class VowelCount {
  
   private static final String INPUT= "C:\\Users\\cr\\Desktop\\input.txt";
   private static final String OUTPUT = "C:\\Users\\cr\\Desktop\\output.txt";

  
   public static void PluralCount(File input,File output){
       ArrayList<Integer>countlist=Vowels.countlist(input);
       Vowels.WriteToFile(output);
   }
  
   public static int countArtical(String word){
       int count=0;
       String [] list_words=word.split(" ");
       for(String s:list_words){
           if(s.toLowerCase().startsWith("a") || s.toLowerCase().startsWith("the") || s.toLowerCase().startsWith("the") ){
               count++;
           }
          
       }
       return count;
   }
   public static ArrayList<String> getVowelList(String s){
       ArrayList<String> list=new ArrayList<String>();

       String [] list_words=s.split(" ");
       for(String word:list_words){
           if(word.toLowerCase().startsWith("a") || word.toLowerCase().startsWith("e") || word.toLowerCase().startsWith("i") || word.toLowerCase().startsWith("o") || word.toLowerCase().startsWith("u")){
               list.add(word);
           }
       }
      
      
       return list;
      
   }
   public static void main(String[] args) throws IOException {
       VowelCount cw=new VowelCount();
       String mlk = "Our lives begin to end the day we become silent about things that matter";
       ArrayList<String>word=getVowelList(mlk);
       Set<String >setarr=new HashSet<String>();
       setarr.addAll(word);
       word.clear();
       word.addAll(setarr);
      
       System.out.println(word.toString());
      
       String theFlea="The flea is a mighty an insect , flea is the most beautiful insect you can ever see the best one";
       System.out.println(countArtical(theFlea));
      
       File input=new File(INPUT);
       File output=new File(OUTPUT);
       PluralCount(input, output);
   }
  
}


Related Solutions

The English alphabet has 26 letters. There are 6 vowels. (a, e, i, o, u, and...
The English alphabet has 26 letters. There are 6 vowels. (a, e, i, o, u, and sometimes y). Suppose we randomly select 8 letters from the alphabet without replacement. Let X = the number of vowels chosen (including y as a vowel). a. How many possible ways are there to select the 8 out of 26 letters (order does not matter) without replacement? b. What is the probability that X = 2 c. What is the probability that X=1? d....
4. The Hawaiian alphabet has twelve letters: five vowels (a, e, i, o, and u) and...
4. The Hawaiian alphabet has twelve letters: five vowels (a, e, i, o, and u) and seven consonants (h, k, l, m, n, p, and w). For the purpose of this exercise we will define an n–letter “word” as an ordered collection of n of these twelve letters with repeats allowed. Obviously, most such “words” will be nonsense words. a) How many possible four–letter Hawaiian “words” are there? b) What is the probability a randomly selected four–letter “word” has no...
How many ways are there to order the 26 letters of the alphabet so that no two of the vowels a, e, i, o,u appear consecutively and the last letter in the ordering is not a vowel?
  (a) How many ways are there to order the 26 letters of the alphabet so that no two of the vowels a, e, i, o,u appear consecutively and the last letter in the ordering is not a vowel? Hint: Every vowel appears to the left of a consonant. (b) How many ways are there to order the 26 letters of the alphabet so that there are at least two consonants immediately following each vowel? (c) In how many different...
Solve the partial differential equation by Laplace transformu_x (x,t)+u_t (x,t)=e^3t given that u(x,o)=0 , u(o,t)=e^3t
Solve the partial differential equation by Laplace transformu_x (x,t)+u_t (x,t)=e^3t given that u(x,o)=0 , u(o,t)=e^3t
1. For this question, we define the following vectors: u = (1, 2), v = (−2,...
1. For this question, we define the following vectors: u = (1, 2), v = (−2, 3). (a) Sketch following vectors on the same set of axes. Make sure to label your axes with a scale. i. 2u ii. −v iii. u + 2v iv. A unit vector which is parallel to v (b) Let w be the vector satisfying u + v + w = 0 (0 is the zero vector). Draw a diagram showing the geometric relationship between...
For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board...
For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board is a 4 by 4 matrix and the numbers on the right are the positon that correspond with the dots. So if player 2 statisfies the requirement for the winning condition. Winning conditions being 4 letters in a row of (all upper case-- Z I C O ), (all straight-line-- Z I i I), (all consonants - Z z C c), (all curved-- C...
I would like to solve the question that is: There are 190 letters and place to...
I would like to solve the question that is: There are 190 letters and place to 10 envelopes (one letter per envelope). What is the prob that exactly 3 envelopes will contain which they should contain? Could you explain why you used the formula as well? Thanks
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do not hard code data file paths or filenames; always ask the user for them. Complete the Monster Attack project by doing the following: In place of the driver used in homework 2, add a menu with a loop and switch (this is already done, ignore this). The user must be able to add attacks, get a report on existing attacks, save a file, retrieve...
12. Assume that we randomly choose from the letters {A, B, C, D, E, F, G,...
12. Assume that we randomly choose from the letters {A, B, C, D, E, F, G, H, I, J, K, L} (without replacing the letters), until they have all been taken. (a) Find the probability that the letters A and K are chosen successively in the given order. (b) Find the probability that the letters G, H, I, are chosen successively in the given order. c) Find the probability that the string "LAI" appears somewhere in the sequence of letters....
Question : As a senior auditor on the E&U accounting firm you are assigned the following...
Question : As a senior auditor on the E&U accounting firm you are assigned the following tasks: 1) Auditing sales and accounts receivable cycle accounts 2) Auditing expenditures & accounts payable cycle accounts 3) Auditing payroll cycle accounts for each of audited cycle mentioned above, prepare a plan that describe the following: -- audit procedure/evidence to be optained note: as you answer give example
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT