SlideShare a Scribd company logo
1 of 4
Download to read offline
Note:****The menu should contain the following options:
Capitalize all words
Lowercase all words
Sample Session
This is an example run of the program. The input and output files are shown after the code.
Please enter the input data file name:
input.txt
Please enter the output data file name:
Output.txt
Choose an option:
Capitalize all words
Lowercase all words
A
Process another file?
Y
Please enter the input data file name:
input.txt
Please enter the output data file name: output2.txt Choose an option:
Capitalize all words
Lowercase all words
B
Process another file? n
Process finished with exit code 0
Output from session
Input file:
line One linE two
Line Three
Output file for option A:
LINE ONE
LINE TWO
LINE THREE
Output file for option B:
line one line two line three Problem Statement mplement the following flow chart in Java. Sart
Request data file Request output yes no Process data 1 of 2 no
Solution
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class FileProcessor {
public static void readFileAndTakeAction(String input, String output, int action)
{
BufferedWriter bw = null;
FileWriter fw = null;
try(BufferedReader br = new BufferedReader(new FileReader(input))) {
fw = new FileWriter(output);
bw = new BufferedWriter(fw);
for(String line; (line = br.readLine()) != null; ) {
if (action == 2) // To lower
{
bw.write(line.toLowerCase());
System.out.println(line.toLowerCase());
}
else // to upper
{
bw.write(line.toUpperCase());
System.out.println(line.toUpperCase());
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while(true)
{
System.out.print("Please enter the input data file name: ");
String input = sc.nextLine();
System.out.print("Please enter the output data file name: ");
String output = sc.nextLine();
System.out.println("Choose an option: ");
System.out.println("A Capitalize all words");
System.out.println("B Lowercase all words");
String actionString = sc.nextLine();
int action = 0;;
if (actionString.equals("A"))
{
action = 1;
}
else
{
action = 2;
}
readFileAndTakeAction(input, output, action);
System.out.println("Process another file?");
String choice = sc.nextLine();
if (choice.equals("Y"))
{
continue;
}
else
{
break;
}
}
System.out.println("Processing finished with exit code 0");
}
}

More Related Content

Similar to NoteThe menu should contain the following optionsCapitalize .pdf

Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
CIS321
 
Data Processing Using Quantum
Data Processing Using QuantumData Processing Using Quantum
Data Processing Using Quantum
nibraspk
 
The problem can be found below. I would like someone to run this. I .pdf
The problem can be found below. I would like someone to run this. I .pdfThe problem can be found below. I would like someone to run this. I .pdf
The problem can be found below. I would like someone to run this. I .pdf
SALES97
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
Abhiraj Bohra
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
f3apparelsonline
 
Problem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docxProblem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docx
rtodd884
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
Vivek Singh
 

Similar to NoteThe menu should contain the following optionsCapitalize .pdf (20)

Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual Develop
 
Data Processing Using Quantum
Data Processing Using QuantumData Processing Using Quantum
Data Processing Using Quantum
 
The problem can be found below. I would like someone to run this. I .pdf
The problem can be found below. I would like someone to run this. I .pdfThe problem can be found below. I would like someone to run this. I .pdf
The problem can be found below. I would like someone to run this. I .pdf
 
Visualbasic tutorial
Visualbasic tutorialVisualbasic tutorial
Visualbasic tutorial
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Message, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type GroupMessage, Debugging, File Transfer and Type Group
Message, Debugging, File Transfer and Type Group
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Learn python
Learn pythonLearn python
Learn python
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
Problem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docxProblem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docx
 
Python basics
Python basicsPython basics
Python basics
 
Unix
UnixUnix
Unix
 
C programming session 14
C programming session 14C programming session 14
C programming session 14
 

More from fedosys

i need the executable file of this program (.exe) This is Assembly.pdf
i need the executable file of this program (.exe) This is Assembly.pdfi need the executable file of this program (.exe) This is Assembly.pdf
i need the executable file of this program (.exe) This is Assembly.pdf
fedosys
 
Help me fix the error shown above in my code of image.cpp please~I.pdf
Help me fix the error shown above in my code of image.cpp please~I.pdfHelp me fix the error shown above in my code of image.cpp please~I.pdf
Help me fix the error shown above in my code of image.cpp please~I.pdf
fedosys
 
Explain how the format of the mark-up language differs from the docu.pdf
Explain how the format of the mark-up language differs from the docu.pdfExplain how the format of the mark-up language differs from the docu.pdf
Explain how the format of the mark-up language differs from the docu.pdf
fedosys
 
Here is the given code, and the things I need to be done. Ive post.pdf
Here is the given code, and the things I need to be done. Ive post.pdfHere is the given code, and the things I need to be done. Ive post.pdf
Here is the given code, and the things I need to be done. Ive post.pdf
fedosys
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
fedosys
 
Describe the attributes that make a vision meaningful to stakeholder.pdf
Describe the attributes that make a vision meaningful to stakeholder.pdfDescribe the attributes that make a vision meaningful to stakeholder.pdf
Describe the attributes that make a vision meaningful to stakeholder.pdf
fedosys
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
fedosys
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
fedosys
 
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdfAssignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
fedosys
 

More from fedosys (20)

If messages are being sent from your email account without your know.pdf
If messages are being sent from your email account without your know.pdfIf messages are being sent from your email account without your know.pdf
If messages are being sent from your email account without your know.pdf
 
Identify some of the postmodern trends movements that women artist .pdf
Identify some of the postmodern trends movements that women artist .pdfIdentify some of the postmodern trends movements that women artist .pdf
Identify some of the postmodern trends movements that women artist .pdf
 
i need the executable file of this program (.exe) This is Assembly.pdf
i need the executable file of this program (.exe) This is Assembly.pdfi need the executable file of this program (.exe) This is Assembly.pdf
i need the executable file of this program (.exe) This is Assembly.pdf
 
Help me fix the error shown above in my code of image.cpp please~I.pdf
Help me fix the error shown above in my code of image.cpp please~I.pdfHelp me fix the error shown above in my code of image.cpp please~I.pdf
Help me fix the error shown above in my code of image.cpp please~I.pdf
 
Explain how the format of the mark-up language differs from the docu.pdf
Explain how the format of the mark-up language differs from the docu.pdfExplain how the format of the mark-up language differs from the docu.pdf
Explain how the format of the mark-up language differs from the docu.pdf
 
Here is the given code, and the things I need to be done. Ive post.pdf
Here is the given code, and the things I need to be done. Ive post.pdfHere is the given code, and the things I need to be done. Ive post.pdf
Here is the given code, and the things I need to be done. Ive post.pdf
 
Each student in my class was given bodily fluids. Everyone was n.pdf
Each student in my class was given bodily fluids. Everyone was n.pdfEach student in my class was given bodily fluids. Everyone was n.pdf
Each student in my class was given bodily fluids. Everyone was n.pdf
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
 
Describe the attributes that make a vision meaningful to stakeholder.pdf
Describe the attributes that make a vision meaningful to stakeholder.pdfDescribe the attributes that make a vision meaningful to stakeholder.pdf
Describe the attributes that make a vision meaningful to stakeholder.pdf
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
 
Compare the DHCP and DHCPv6SolutionThe comparison between the .pdf
Compare the DHCP and DHCPv6SolutionThe comparison between the .pdfCompare the DHCP and DHCPv6SolutionThe comparison between the .pdf
Compare the DHCP and DHCPv6SolutionThe comparison between the .pdf
 
Consider in a given economy For a given time period the following in.pdf
Consider in a given economy For a given time period the following in.pdfConsider in a given economy For a given time period the following in.pdf
Consider in a given economy For a given time period the following in.pdf
 
Background Many cities such as Detroit, MI have been in the news re.pdf
Background Many cities such as Detroit, MI have been in the news re.pdfBackground Many cities such as Detroit, MI have been in the news re.pdf
Background Many cities such as Detroit, MI have been in the news re.pdf
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
 
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdfAssignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
Assignment 1. List the three visual elements Brieny descrbe each. 2 W.pdf
 
A. Intergenic sequences make up 60 of the human genome. Where do t.pdf
A. Intergenic sequences make up 60 of the human genome. Where do t.pdfA. Intergenic sequences make up 60 of the human genome. Where do t.pdf
A. Intergenic sequences make up 60 of the human genome. Where do t.pdf
 
a) How can habitat selection and sexual selection drive sympatric sp.pdf
a) How can habitat selection and sexual selection drive sympatric sp.pdfa) How can habitat selection and sexual selection drive sympatric sp.pdf
a) How can habitat selection and sexual selection drive sympatric sp.pdf
 
A common test of balances in a revenue cycle is the inquiry of manage.pdf
A common test of balances in a revenue cycle is the inquiry of manage.pdfA common test of balances in a revenue cycle is the inquiry of manage.pdf
A common test of balances in a revenue cycle is the inquiry of manage.pdf
 
7. Recently, Skooterville has experienced a large growth in populati.pdf
7. Recently, Skooterville has experienced a large growth in populati.pdf7. Recently, Skooterville has experienced a large growth in populati.pdf
7. Recently, Skooterville has experienced a large growth in populati.pdf
 
50mL of a 0.1000 M aqueous solution of hydrazoic acid (HN3, Ka=1.91.pdf
50mL of a 0.1000 M aqueous solution of hydrazoic acid (HN3, Ka=1.91.pdf50mL of a 0.1000 M aqueous solution of hydrazoic acid (HN3, Ka=1.91.pdf
50mL of a 0.1000 M aqueous solution of hydrazoic acid (HN3, Ka=1.91.pdf
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 

NoteThe menu should contain the following optionsCapitalize .pdf

  • 1. Note:****The menu should contain the following options: Capitalize all words Lowercase all words Sample Session This is an example run of the program. The input and output files are shown after the code. Please enter the input data file name: input.txt Please enter the output data file name: Output.txt Choose an option: Capitalize all words Lowercase all words A Process another file? Y Please enter the input data file name: input.txt Please enter the output data file name: output2.txt Choose an option: Capitalize all words Lowercase all words B Process another file? n Process finished with exit code 0 Output from session Input file: line One linE two Line Three Output file for option A: LINE ONE LINE TWO LINE THREE Output file for option B: line one line two line three Problem Statement mplement the following flow chart in Java. Sart Request data file Request output yes no Process data 1 of 2 no
  • 2. Solution import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class FileProcessor { public static void readFileAndTakeAction(String input, String output, int action) { BufferedWriter bw = null; FileWriter fw = null; try(BufferedReader br = new BufferedReader(new FileReader(input))) { fw = new FileWriter(output); bw = new BufferedWriter(fw); for(String line; (line = br.readLine()) != null; ) { if (action == 2) // To lower { bw.write(line.toLowerCase()); System.out.println(line.toLowerCase()); } else // to upper { bw.write(line.toUpperCase()); System.out.println(line.toUpperCase()); } } } catch (FileNotFoundException e) { System.out.println("File not found"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
  • 3. } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { System.out.print("Please enter the input data file name: "); String input = sc.nextLine(); System.out.print("Please enter the output data file name: "); String output = sc.nextLine(); System.out.println("Choose an option: "); System.out.println("A Capitalize all words"); System.out.println("B Lowercase all words"); String actionString = sc.nextLine(); int action = 0;; if (actionString.equals("A")) { action = 1; } else { action = 2; } readFileAndTakeAction(input, output, action); System.out.println("Process another file?"); String choice = sc.nextLine(); if (choice.equals("Y")) { continue; } else