Question

LANGUAGE = JAVA (IDE Eclipse preferred) Lab 21 AEIOU Counter Objective: Write a program that reads...

LANGUAGE = JAVA

(IDE Eclipse preferred)

Lab 21

AEIOU Counter

Objective:

Write a program that reads a file and counts the number of times the vowels ‘A’, ‘E’, ‘I’, ‘O’, ‘U’ occurs exactly in that order.

  • It ignores consonants
  • It ignores any type of space
  • It ignores case
  • The only thing it cannot ignore is if another vowel occurs out of order
  • These count
    • AEIOU
    • aeiou
    • hahehihohu
    • Take it out
  • These do not
    • AEIuO
    • Taco is good
    • Take it over
  • Files to Test
    • file1.txt
    • file2.txt
    • file3.txt
    • file4.txt

Hints and Tips:

  • It may be a good idea to build one long string and use .charAt to examine each loop
  • There may be many nested loops

Example Dialog 1:

Enter a file name and I will say how many times AEIOU appears in order

file1.txt

The file file1.txt has "AEIOU" appears in order 7 times

Example Dialog 2:

Enter a file name and I will say how many times AEIOU appears in order

file2.txt

The file file2.txt has "AEIOU" appears in order 1 times

Example Dialog 3:

Enter a file name and I will say how many times AEIOU appears in order

file3.txt

The file file3.txt has "AEIOU" appears in order 0 times

Example Dialog 4:

Enter a file name and I will say how many times AEIOU appears in order

file4.txt

The file file4.txt has "AEIOU" appears in order 209 times

Lab Report Questions:

1. When performing File I/O, what must one use in order to handle the related exceptions?

2. Is it possible to go backwards (or to a previous point) in a file using a Scanner?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.io.*;

public class Vowels
{
   public static void main(String[] args)
   {
       File file = new File("file1.txt");       /* keep the text file in c drive or else give the full location of the
the file otherwise it will give file not found exception */
       try
       {
       Scanner input = new Scanner(file);
       String content_of_file = "";
       int counter = 0;

       while (input.hasNext())
       {
       content_of_file = content_of_file + input.next() + " ";
       }
       input.close();

       char[] charArr = content_of_file.toCharArray(); /* converting string into character and storing it into an array then it will compare each character with the condition */


       for (char c : charArr)
       {
       if(c == 'a' || c == 'e' ||c == 'i' ||c == 'o' ||c == 'u')
           counter++;
       }

       System.out.println("The file " + file + " has AEIOU in order " + counter + " times \n");

       }

       catch(FileNotFoundException exception)
       {
           System.out.println("Unable to open file '" + file + "'");
       }
       catch(Exception exception)
       {
           System.out.println( "Error reading file '" + file + "'");
       }
   }
}

OutPut :

Q1.  When performing File I/O, what must one use in order to handle the related exceptions?

Ans. While preforming File I/O atleast we should be "FileNotFoundException". And to handel other unknown Exception we can create object of Exception class and catch that exception.

Q2 Is it possible to go backwards (or to a previous point) in a file using a Scanner?

Ans. No it is not possible to backwards or to a previous point because the scanner scans only one time from starting to ending

Add a comment
Know the answer?
Add Answer to:
LANGUAGE = JAVA (IDE Eclipse preferred) Lab 21 AEIOU Counter Objective: Write a program that reads...
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
  • C Program Question: Write a program that reads all integers that are in the range of...

    C Program Question: Write a program that reads all integers that are in the range of 0 to 100, inclusive from an input file named: a.txt and counts how many occurrences of each are in the file. After all input has been processed, display all the values with the number of occurrences that were in are in the input file. Note: The program ignores any number less than 0 or greater than 100. Note: Do not display zero if a...

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

  • In C language This program reads in a series of words. All words consist of only...

    In C language This program reads in a series of words. All words consist of only lower-case letters ('a' through 'z'). None of the words entered will be longer than 50 letters. The program reads until ctrl-d (end-of-file), and then prints out all the lower-case letters that were missing in the input or a statement indicating the input has all the letters. Two executions of the program are shown below. Enter your input: the quick brown fox jumps over the...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • JAVA Code: Complete the program that reads from a text file and counts the occurrence of...

    JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...

  • using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File;...

    using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File; public class { public static void main(String[] args) { // Create a new Scanner object to obtain // input from System.in // --> TODO // Ask user for a word to search for. Print // out a prompt // --> TODO // Use the Scanner object you created above to // take a word of input from the user. // --> TODO // ***...

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

  • Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the...

    Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the names of the teams that won the Super Bowl from 1967 through 2019. Write a program that repeatedly allows a user to enter a team name and then displays the number of times and the years in which that team won the Super Bowl. If the team entered by the user has never won the Super Bowl, report that to the user instead. For...

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