Please write in Dr. JAVA and write notes if possible. *In Dr. JAVA* Write the fo
ID: 3711285 • Letter: P
Question
Please write in Dr. JAVA and write notes if possible.
*In Dr. JAVA* Write the following code Write a program that reads a file and counts the number of times the vowels 'A', 'E T, ?,, ‘U, occurs exactly in that order. . It ignores consonants . It ignores any tvpe of space . It ignores case . The only thing it cannot ignore is if another vowel occurs out of order . These count AEIOU o aeiou o Take it out . These do not o Taco is good o Take it over 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: The file blah.txt has "AEIOU" in order 7 timesExplanation / Answer
import java.util.*;
import java.io.*;
public class read {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.io.File file = new java.io.File("C:\Users\Scorpio\Desktop\vowels.txt"); //you need to change path according to your file path
Scanner input = null;
try {
input = new Scanner(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String totalfileContent = "";
String fileContent = "";
while (input.hasNext())
{
totalfileContent += input.next().toLowerCase();
}
input.close();
for (int i = 0; i<totalfileContent.length();i++)
{
if(totalfileContent.charAt(i) == 'a' ||totalfileContent.charAt(i) == 'e' ||totalfileContent.charAt(i) == 'i' ||totalfileContent.charAt(i) == 'o' ||totalfileContent.charAt(i) == 'u')
{
char ch=totalfileContent.charAt(i);
String temp=Character.toString(ch);
fileContent=fileContent+temp;
}
}
int counter = 0;
for (int i = 0; i<fileContent.length()-4;i++)
{
if(fileContent.charAt(i) == 'a'){
if(fileContent.charAt(i+1)=='e'){
if(fileContent.charAt(i+2)=='i')
if(fileContent.charAt(i+3)=='o')
if(fileContent.charAt(i+4)=='u'){
counter++;
}
}
}
}
System.out.println("The file vowels.txt has AEIOU in order " + counter + " times");
}
}