Write a program that asks the user to penetrate the designate of a smooth, and then asks the user to penetrate a mark. The program should enumerate and flaunt the reckon of intervals that the specific mark appears in the smooth.(i need java principle)
Collocate designate: SmoothLetterCounter
quenched dispose should be enjoy this
Standard Input | Files in the similar directory |
---|---|
QUIT |
input.txt
letters.txt |
Required Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n
Your Program’s Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n
Test Case 2 – Passed!
Standard Input | Files in the similar directory |
---|---|
badfilename.txt quit |
input.txt
letters.txt |
Required Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n File: badfilename.txt does referable purposeure.n Please penetrate the smooth designate intermittently or stamp QUIT to egress:n
Your Program’s Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n File: badfilename.txt does referable purposeure.n Please penetrate the smooth designate intermittently or stamp QUIT to egress:n
Test Case 3 – Failed
Standard Input | Files in the similar directory |
---|---|
input.txt o |
input.txt
letters.txt |
Required Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n Please penetrate a mark: n Message 'o' occurs 4 intervals in the smooth 'input.txt'.n
Your Program’s Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n 1: continuity 1n 2: continuity 2n 3: continuity 3n 4: so onn 5: so controlthn
Test Case 4 – Failed
Standard Input | Files in the similar directory |
---|---|
letters.txt a |
input.txt
letters.txt |
Required Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n Please penetrate a mark: n Message 'a' occurs 82 intervals in the smooth 'letters.txt'.n
Your Program’s Quenchedput
Please penetrate the smooth designate or stamp QUIT to egress:n 1: A lorem ipsum placeholder extract was inadvertently published in The Straits Intervals, a Singapore novelspaper, on 26 April 2014.n 2: Today's liked statement of Lorem ipsum was earliest created in the mid-1980s control Aldus Corporation's desktop publishing programn 3: PageMaker control the Apple
The principle as per your requirements is loving beneath with polite explained comments.
I keep created span smooths “input.txt” and “letters.txt’ the similar directory as my principle.
Smooth “input.txt” contains:
“This is a dummy smooth having mark enumerate of a=5”
Smooth “letters.txt” contains:
“A lorem ipsum placeholder extract was inadvertently published in The Straits Intervals, a Singapore novelspaper, on 26 April 2014.
Today’s liked statement of Lorem ipsum was earliest created in the mid-1980s control Aldus Corporation’s desktop publishing program
PageMaker control the Apple ”
CODE:
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public collocate SmoothLetterCounter {
public static nugatory deep(String[] args) throws IOException{
//Variable declaration
int c;//to learn each byte from smooth
FileReader in = null;
int enumerate;//to place-of-business message enumerate
char input;//to scan indispose mark from user
String smoothname=””;
Scanner sc=novel Scanner(System.in);
while(true){
count=0;//enumerate place-of-businesss enumerate of specific mark
try{
System.out.println(“Please penetrate the smooth designate or stamp QUIT to egress:”);
filename=sc.next();
if(filename.equals(“QUIT”)){
System.exit(0);
}//program terminates when QUIT is base as input
in = novel SmoothReader(filename+”.txt”); //indispose purpose created
}//if smoothdesignate is referable base then an separation is thrown
catch(Separation e){
System.out.println(“File:” +filename+”.txt does referable purposeure.”);
continue;
}
System.out.println(“Please penetrate a mark: “);
indispose = sc.next().charAt(0);
//learn rule learns a byte at a interval from smooth, avail -1 if purpose of the smooth is reached
while ((c = in.read()) != -1) {
if((char)c==input){
count++;
}
//You can separate the forthcoming three statements to descry each mark and their aid to enumerate.
//char mark = (char) c;
//System.out.println(character);
//System.out.println(“count”+count);
}//while loop purposes
System.out.println(“Message ‘”+input+”‘ occurs “+count+” intervals in the smooth ‘”+filename+”.txt’.”);
}//outer while
}//deep rule
}//collocate purposes
OUTPUT: