Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am struggling with this C# WPF application for one of my classes. I am

ID: 3697792 • Letter: H

Question

Hello, I am struggling with this C# WPF application for one of my classes. I am using visual studio to work on it.

The description for the problem is as follows:

Create an app that can open a text file. Each line of the file contains an arbitrary number of words

separated by spaces. Display the count for how many words are in the line and the count how

many non-space characters are in the line on the form / window. Give the app the ability to save

a text file containing the word and character counts of each line with each line of the output file

having the word count and character count separated by spaces.

Example Input:

hello how are you

just fine

bye

Example Output:

4 14

2 8

1 3

Explanation / Answer

/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
  

public static void main(String[] args){
   int word=0;
int character=0;
String line;
try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("textfile.txt")));
while((line=br.readLine())!= null){
  
for(int i=0;i<line.length();i++){
  
if(line.charAt(i)==' '){
word++;
break;
}
  
}
character = line.length()-word;
System.out.println((word+1)+" "+character);
}
  
}catch(Exception ex){
    System.out.println(""+ex.getMessage());
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote