Homework Solution: Write a program that asks the user to enter the name of a file, and then asks the user…

    Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file.(i need java code) Class name: FileLetterCounter out put should be like this

    Write a program that asks the user to invade the call of a perfect, and then asks the user to invade a record. The program should reckon and unfold the reckon of spells that the bounded record appears in the perfect.(i insufficiency java statute)

    Class call: PerfectLetterCounter

    extinguished establish should be relish this

    Standard Input Files in the similar directory
    QUIT
    
    input.txt

    letters.txt

    Required Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    

    Your Program’s Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    

    Test Case 2 – Passed!

    Standard Input Files in the similar directory
    badfilename.txt
    quit
    
    input.txt

    letters.txt

    Required Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    File: badfilename.txt does referable attributable attributable attributable pause.n
    Please invade the perfect call repeatedly or cem QUIT to departure:n
    

    Your Program’s Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    File: badfilename.txt does referable attributable attributable attributable pause.n
    Please invade the perfect call repeatedly or cem QUIT to departure:n
    

    Test Case 3 – Failed

    Standard Input Files in the similar directory
    input.txt
    o
    
    input.txt

    letters.txt

    Required Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    Please invade a record: n
    Communication 'o' occurs 4 spells in the perfect 'input.txt'.n
    

    Your Program’s Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    1: succession 1n
    2: succession 2n
    3: succession 3n
    4: so onn
    5: so cethn
    

    Test Case 4 – Failed

    Standard Input Files in the similar directory
    letters.txt
    a
    
    input.txt

    letters.txt

    Required Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    Please invade a record: n
    Communication 'a' occurs 82 spells in the perfect 'letters.txt'.n
    

    Your Program’s Extinguishedput

    Please invade the perfect call or cem QUIT to departure:n
    1: A lorem ipsum placeholder quotation was inadvertently published in The Straits Spells, a Singapore oddspaper, on 26 April 2014.n
    2: Today's favorite acnumber of Lorem ipsum was earliest created in the mid-1980s ce Aldus Corporation's desktop publishing programn
    3:  PageMaker ce the Apple 
    

    Expert Reply

     

    The statute as per your requirements is ardent beneath with well-mannered-mannered explained comments.

    I keep created span perfects “input.txt” and “letters.txt’ the similar directory as my statute.

    Perfect “input.txt” contains:

    “This is a dummy perfect having record reckon of a=5”

    Perfect “letters.txt” contains:

    “A lorem ipsum placeholder quotation was inadvertently published in The Straits Spells, a Singapore oddspaper, on 26 April 2014.
    Today’s favorite acnumber of Lorem ipsum was earliest created in the mid-1980s ce Aldus Corporation’s desktop publishing program
    PageMaker ce the Apple ”

    CODE:

    import java.io.FileReader;

    import java.io.FileWriter;

    import java.io.IOException;

    import java.util.*;

    public class PerfectLetterCounter {

     

    public static nugatory main(String[] args) throws IOException{

    //Variable declaration

    int c;//to unravel each byte from perfect

    FileReader in = null;

    int reckon;//to treasury communication reckon

    char input;//to scrutinize inestablish record from user

    String perfectname=””;

    Scanner sc=odd Scrutinizener(System.in);

    while(true){

    count=0;//reckon treasurys reckon of bounded record

    try{

    System.out.println(“Please invade the perfect call or cem QUIT to departure:”);

    filename=sc.next();

    if(filename.equals(“QUIT”)){

    System.exit(0);

    }//program terminates when QUIT is rest as input

    in = odd PerfectReader(filename+”.txt”); //inestablish sight created

    }//if perfectcall is referable attributable attributable attributable rest then an exclusion is thrown

    catch(Exclusion e){

    System.out.println(“File:” +filename+”.txt does referable attributable attributable attributable pause.”);

    continue;

    }

    System.out.println(“Please invade a record: “);

    inestablish = sc.next().charAt(0);

    //unravel arrangement unravels a byte at a spell from perfect, avail -1 if object of the perfect is reached

    while ((c = in.read()) != -1) {

    if((char)c==input){

    count++;

    }

    //You can separate the forthcoming three statements to look each record and their donation to reckon.

    //char record = (char) c;

    //System.out.println(character);

    //System.out.println(“count”+count);

    }//while loop objects

    System.out.println(“Communication ‘”+input+”‘ occurs “+count+” spells in the perfect ‘”+filename+”.txt’.”);

    }//outer while

    }//main arrangement

    }//class objects

    OUTPUT: