SlideShare a Scribd company logo
1 of 3
Download to read offline
Create a document with a form that registers all non-profit organizations in the area, the number
of members they have, and the type of organization. After the user enters data in all the fields
and presses the button, your program will create a single text le that saves information for each
organization on a separate line. The name of the data file is np.txt. This data file should be
created in the same directory as your running program, without hard-coding the file path to
ensure portability.
In the data file please include the Organization name, Membership, and Type, separated by
commas. Membership should only accept numbers, Type should only accept the following
strings: Educational, Animal Rescue, Religious, Food Service, and misspellings should not be
allowed. The first line of the output will be the headers. You can make up all the names and
numbers while you are testing your programs.
Sample Output written to a file will look as following:
Organization, Membership, Type
Meals on Trucks, 123, Food Service
The Church of Purple Cross, 34, Religious
Kitties and Puppies, 1234, Animal Rescue
Solution
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class WriteToFile {
private static final String FILENAME = "np.txt.";
private static Scanner s;
static int mem;
static String org, type;
static int getMem() {
System.out.println("Enter Membership Number: ");
return s.nextInt();
}
public static void main(String[] args) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME))) {
boolean isMore = true;
s = new Scanner(System.in);
String content = "Organization, Membership, Type";
bw.write(content);
while (isMore) {
System.out.println("Enter Organization Name: ");
org = s.nextLine();
try {
System.out.println("Enter Membership Number: ");
mem = s.nextInt();
} catch (Exception e) {
System.out.println("Membership Should only be of Number Type");
mem = getMem();
}
boolean end = false;
do {
System.out.println("Enter Type Of Organization: ");
type = s.next();
switch (type) {
case "Educational":
break;
case "Animal Rescue":
break;
case "Religious":
break;
case "Food Service":
break;
default:
{
System.out.println(
"Type Name Should be Only Educational, Animal Rescue ,Religious ,Food
Service");
end = true;
}
}
} while (end);
String f=org+","+mem+","+type;
bw.newLine();
bw.append(f);
System.out.println("Enter More Enteries?(y/n) :");
if(s.next().equals("n"))
isMore=false;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

More Related Content

Similar to Create a document with a form that registers all non-profit organiza.pdf

Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
secunderbadtirumalgi
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdf
rishabjain5053
 
Write a C++ program that reads in a list of first and last names fro.pdf
Write a C++ program that reads in a list of first and last names fro.pdfWrite a C++ program that reads in a list of first and last names fro.pdf
Write a C++ program that reads in a list of first and last names fro.pdf
ramasamyarm
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
alfred4lewis58146
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
atulkapoor33
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
dickonsondorris
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
shahidqamar17
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...
hwbloom3
 

Similar to Create a document with a form that registers all non-profit organiza.pdf (20)

python file handling
python file handlingpython file handling
python file handling
 
There are many different tools available to forensic investigato.docx
There are many different tools available to forensic investigato.docxThere are many different tools available to forensic investigato.docx
There are many different tools available to forensic investigato.docx
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
Registry forensics
Registry forensicsRegistry forensics
Registry forensics
 
D2L Site Admin Tools Discussion at Brightspace South Carolina Connection
D2L Site Admin Tools Discussion at Brightspace South Carolina ConnectionD2L Site Admin Tools Discussion at Brightspace South Carolina Connection
D2L Site Admin Tools Discussion at Brightspace South Carolina Connection
 
Xpsupport
XpsupportXpsupport
Xpsupport
 
Austin Powell - Digital Forensic Case Study.pdf
Austin Powell - Digital Forensic Case Study.pdfAustin Powell - Digital Forensic Case Study.pdf
Austin Powell - Digital Forensic Case Study.pdf
 
Need help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdfNeed help with this java code. fill in lines where needed. Also, not.pdf
Need help with this java code. fill in lines where needed. Also, not.pdf
 
Write a C++ program that reads in a list of first and last names fro.pdf
Write a C++ program that reads in a list of first and last names fro.pdfWrite a C++ program that reads in a list of first and last names fro.pdf
Write a C++ program that reads in a list of first and last names fro.pdf
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Apache tika
Apache tikaApache tika
Apache tika
 
Eventlog
EventlogEventlog
Eventlog
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R  6.docxCopyright © 2018 Pearson Education, Inc. C H A P T E R  6.docx
Copyright © 2018 Pearson Education, Inc. C H A P T E R 6.docx
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 

More from rohit219406

Below are the transactions and adjustments that occurred during the .pdf
Below are the transactions and adjustments that occurred during the .pdfBelow are the transactions and adjustments that occurred during the .pdf
Below are the transactions and adjustments that occurred during the .pdf
rohit219406
 
As a software developer you have been delegated with the assignment .pdf
As a software developer you have been delegated with the assignment .pdfAs a software developer you have been delegated with the assignment .pdf
As a software developer you have been delegated with the assignment .pdf
rohit219406
 
Why do countries with high GNI and GDP are attractive for foreign in.pdf
Why do countries with high GNI and GDP are attractive for foreign in.pdfWhy do countries with high GNI and GDP are attractive for foreign in.pdf
Why do countries with high GNI and GDP are attractive for foreign in.pdf
rohit219406
 
Use what you have learned so far to bring variety in your writing. U.pdf
Use what you have learned so far to bring variety in your writing. U.pdfUse what you have learned so far to bring variety in your writing. U.pdf
Use what you have learned so far to bring variety in your writing. U.pdf
rohit219406
 
The Blackbeard Company Ltd provided the following information in reg.pdf
The Blackbeard Company Ltd provided the following information in reg.pdfThe Blackbeard Company Ltd provided the following information in reg.pdf
The Blackbeard Company Ltd provided the following information in reg.pdf
rohit219406
 
Thank you 1. What is responsible for anteriorposterior axis formati.pdf
Thank you 1. What is responsible for anteriorposterior axis formati.pdfThank you 1. What is responsible for anteriorposterior axis formati.pdf
Thank you 1. What is responsible for anteriorposterior axis formati.pdf
rohit219406
 
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdfTake the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
rohit219406
 
Systems analysis project 10 can you answer the 4 questions at the t.pdf
Systems analysis project 10 can you answer the 4 questions at the t.pdfSystems analysis project 10 can you answer the 4 questions at the t.pdf
Systems analysis project 10 can you answer the 4 questions at the t.pdf
rohit219406
 
Step 1. Read critically and analyze the following scenarioGeraldi.pdf
Step 1. Read critically and analyze the following scenarioGeraldi.pdfStep 1. Read critically and analyze the following scenarioGeraldi.pdf
Step 1. Read critically and analyze the following scenarioGeraldi.pdf
rohit219406
 
Microscopes and telescopes both consist of two converging lenses cont.pdf
Microscopes and telescopes both consist of two converging lenses cont.pdfMicroscopes and telescopes both consist of two converging lenses cont.pdf
Microscopes and telescopes both consist of two converging lenses cont.pdf
rohit219406
 

More from rohit219406 (20)

Below are the transactions and adjustments that occurred during the .pdf
Below are the transactions and adjustments that occurred during the .pdfBelow are the transactions and adjustments that occurred during the .pdf
Below are the transactions and adjustments that occurred during the .pdf
 
Help Please. Results not given Explain how your results for the pe.pdf
Help Please. Results not given Explain how your results for the pe.pdfHelp Please. Results not given Explain how your results for the pe.pdf
Help Please. Results not given Explain how your results for the pe.pdf
 
As a software developer you have been delegated with the assignment .pdf
As a software developer you have been delegated with the assignment .pdfAs a software developer you have been delegated with the assignment .pdf
As a software developer you have been delegated with the assignment .pdf
 
What scientist is credited with proposing the equivalency of mass and.pdf
What scientist is credited with proposing the equivalency of mass and.pdfWhat scientist is credited with proposing the equivalency of mass and.pdf
What scientist is credited with proposing the equivalency of mass and.pdf
 
Why do countries with high GNI and GDP are attractive for foreign in.pdf
Why do countries with high GNI and GDP are attractive for foreign in.pdfWhy do countries with high GNI and GDP are attractive for foreign in.pdf
Why do countries with high GNI and GDP are attractive for foreign in.pdf
 
Which of the following is NOT true about the ESCBA.It acts as an.pdf
Which of the following is NOT true about the ESCBA.It acts as an.pdfWhich of the following is NOT true about the ESCBA.It acts as an.pdf
Which of the following is NOT true about the ESCBA.It acts as an.pdf
 
What is 4 -4 + infinity - infinity As x approaches 3 from th.pdf
What is  4  -4  + infinity  - infinity  As x approaches 3 from th.pdfWhat is  4  -4  + infinity  - infinity  As x approaches 3 from th.pdf
What is 4 -4 + infinity - infinity As x approaches 3 from th.pdf
 
Use what you have learned so far to bring variety in your writing. U.pdf
Use what you have learned so far to bring variety in your writing. U.pdfUse what you have learned so far to bring variety in your writing. U.pdf
Use what you have learned so far to bring variety in your writing. U.pdf
 
Use C programmingMake sure everything works only uploadSol.pdf
Use C programmingMake sure everything works only uploadSol.pdfUse C programmingMake sure everything works only uploadSol.pdf
Use C programmingMake sure everything works only uploadSol.pdf
 
Thoroughly describe the molecular underpinnings of ONE and only one.pdf
Thoroughly describe the molecular underpinnings of ONE and only one.pdfThoroughly describe the molecular underpinnings of ONE and only one.pdf
Thoroughly describe the molecular underpinnings of ONE and only one.pdf
 
The Blackbeard Company Ltd provided the following information in reg.pdf
The Blackbeard Company Ltd provided the following information in reg.pdfThe Blackbeard Company Ltd provided the following information in reg.pdf
The Blackbeard Company Ltd provided the following information in reg.pdf
 
Thank you 1. What is responsible for anteriorposterior axis formati.pdf
Thank you 1. What is responsible for anteriorposterior axis formati.pdfThank you 1. What is responsible for anteriorposterior axis formati.pdf
Thank you 1. What is responsible for anteriorposterior axis formati.pdf
 
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdfTake the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
Take the basic Hardy-Weinberg Equilibrium equation, where there are a.pdf
 
Systems analysis project 10 can you answer the 4 questions at the t.pdf
Systems analysis project 10 can you answer the 4 questions at the t.pdfSystems analysis project 10 can you answer the 4 questions at the t.pdf
Systems analysis project 10 can you answer the 4 questions at the t.pdf
 
Step 1. Read critically and analyze the following scenarioGeraldi.pdf
Step 1. Read critically and analyze the following scenarioGeraldi.pdfStep 1. Read critically and analyze the following scenarioGeraldi.pdf
Step 1. Read critically and analyze the following scenarioGeraldi.pdf
 
Question 3 2 pts In response to the Great Recession, the Federal Rese.pdf
Question 3 2 pts In response to the Great Recession, the Federal Rese.pdfQuestion 3 2 pts In response to the Great Recession, the Federal Rese.pdf
Question 3 2 pts In response to the Great Recession, the Federal Rese.pdf
 
Prove that the T_i -property is a topological property for i = 0S.pdf
Prove that the T_i -property is a topological property for i = 0S.pdfProve that the T_i -property is a topological property for i = 0S.pdf
Prove that the T_i -property is a topological property for i = 0S.pdf
 
Q4.14. Which of the following species is most likely to exhibit pate.pdf
Q4.14. Which of the following species is most likely to exhibit pate.pdfQ4.14. Which of the following species is most likely to exhibit pate.pdf
Q4.14. Which of the following species is most likely to exhibit pate.pdf
 
Prepare a classified balance sheet. Do not show the components that .pdf
Prepare a classified balance sheet. Do not show the components that .pdfPrepare a classified balance sheet. Do not show the components that .pdf
Prepare a classified balance sheet. Do not show the components that .pdf
 
Microscopes and telescopes both consist of two converging lenses cont.pdf
Microscopes and telescopes both consist of two converging lenses cont.pdfMicroscopes and telescopes both consist of two converging lenses cont.pdf
Microscopes and telescopes both consist of two converging lenses cont.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
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
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
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...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
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
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 

Create a document with a form that registers all non-profit organiza.pdf

  • 1. Create a document with a form that registers all non-profit organizations in the area, the number of members they have, and the type of organization. After the user enters data in all the fields and presses the button, your program will create a single text le that saves information for each organization on a separate line. The name of the data file is np.txt. This data file should be created in the same directory as your running program, without hard-coding the file path to ensure portability. In the data file please include the Organization name, Membership, and Type, separated by commas. Membership should only accept numbers, Type should only accept the following strings: Educational, Animal Rescue, Religious, Food Service, and misspellings should not be allowed. The first line of the output will be the headers. You can make up all the names and numbers while you are testing your programs. Sample Output written to a file will look as following: Organization, Membership, Type Meals on Trucks, 123, Food Service The Church of Purple Cross, 34, Religious Kitties and Puppies, 1234, Animal Rescue Solution import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class WriteToFile { private static final String FILENAME = "np.txt."; private static Scanner s; static int mem; static String org, type; static int getMem() { System.out.println("Enter Membership Number: "); return s.nextInt(); } public static void main(String[] args) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME))) { boolean isMore = true;
  • 2. s = new Scanner(System.in); String content = "Organization, Membership, Type"; bw.write(content); while (isMore) { System.out.println("Enter Organization Name: "); org = s.nextLine(); try { System.out.println("Enter Membership Number: "); mem = s.nextInt(); } catch (Exception e) { System.out.println("Membership Should only be of Number Type"); mem = getMem(); } boolean end = false; do { System.out.println("Enter Type Of Organization: "); type = s.next(); switch (type) { case "Educational": break; case "Animal Rescue": break; case "Religious": break; case "Food Service": break; default: { System.out.println( "Type Name Should be Only Educational, Animal Rescue ,Religious ,Food Service"); end = true; } } } while (end);
  • 3. String f=org+","+mem+","+type; bw.newLine(); bw.append(f); System.out.println("Enter More Enteries?(y/n) :"); if(s.next().equals("n")) isMore=false; } } catch (IOException e) { e.printStackTrace(); } } }