Question: JAva eclipse I need help Write a program that prompts the user to enter a file name, then opens the file in text mode and
JAva eclipse I need help
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it line by line. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name.
The file can contain one or more sentences. The program should accept as input each sentence in which all the words are run together, but the first character of each word is uppercase. Convert sentences to strings in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses. would be converted to Stop and smell the roses. Sentences are separated by periods ('.'), exclamation marks ('!'), or question marks ('?'). Ensure that there is one space character in between sentences.
_______________________________________________________________________
Current code.
import java.io.*; import java.util.Scanner; class WordConvert{ public static void main(String []arg) throws Exception{ Scanner sc = new Scanner(System.in); System.out.println("Please enter the file name or type QUIT to exit."); while(true){ String input = sc.next(); if(input.compareTo("QUIT") == 0){ break; }else{ String filePath = new File("").getAbsolutePath(); filePath = filePath.concat("/"); filePath = filePath.concat(input); File file = new File(filePath); if(file.exists() && !file.isDirectory()){ BufferedReader br = new BufferedReader(new FileReader(file)); String st; while((st = br.readLine()) != null){ String []sentences = st.split(" "); for(int i=0;i
______________________________________________________________________________
Current output it gives me is like this: The first letter after the first sentence isnt capitalized: I need help.
A true rebel you are! everyone was impressed. you'll do well to continue in the same spirit. Please explain a bit more in the way of footnotes. from the given text it's not clear what are we reading about.
I need it like this:
A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit. Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
