Write a
Program plan:
- Include the required header files.
- Create a class “Gettysburg”.
- Define main function.
- Declare a variable “filename” with the value as file name.
- In “try” block,
- Create an object for “PrintWriter” class and pass the parameter as “filename”.
- Write the contents into the file.
- Close the file.
- In “catch” block,
- If the file not found in the folder, throw a “FileNotFoundException”.
- Display the statement.
- Define main function.
Explanation of Solution
Program:
//import the header file
import java.io.*;
//definition of "Gettysburg" class
public class Gettysburg
{
//definition of main method
public static void main(String[] args)
{
//declare the variable and assign the filename
String filename = "gettysburg.txt";
//try block
try
{
/*create object for "PrintWriter" class and pass the file name*/
PrintWriter outputStream = new PrintWriter(filename);
//write the contents to the file
outputStream.println("Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.");
outputStream.println("Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure.");
outputStream.println("We are met on a great battle-field of that war.");
outputStream.println("We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live.");
outputStream.println("It is altogether fitting and proper that we should do this.");
outputStream.println("But, in a larger sense, we can not dedicate-we can not consecrate-we can not hallow-this ground.");
outputStream.println("The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract.");
outputStream.println("The world will little note, nor long remember what we say here, but it can never forget what they did here.");
outputStream.println("It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. ");
outputStream.println("It is rather for us to be here dedicated to the great task remaining before us - that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion - that we here highly resolve that these dead shall not have died in vain - that this nation, under God, shall have a new birth of freedom - and that government of the people, by the people, for the people, shall not perish from the earth.");
//close the file
outputStream.close();
}
//catch block
catch(FileNotFoundException e)
{
//display the error message
System.out.println("Error opening the file " + filename);
//exit the program
System.exit(0);
}
//display the message
System.out.println("The file gettysburg.txt has been written.");
}
}
Output:
The file gettysburg.txt has been written.
Output file:
Screenshot of “gettysburg.txt” text file
Want to see more full solutions like this?
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out With Visual Basic (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Modern Database Management
Degarmo's Materials And Processes In Manufacturing
- As described in Learning from Mistakes, the failure of the A380 to reach its sales goals was due to Multiple Choice: a) misunderstanding of supplier demands. b) good selection of hotel in the sky amenities. c) changes in customer demands. d) lack of production capacity.arrow_forwardNumerous equally balanced competitors selling products that lack differentiation in a slow growth industry are most likely to experience high: a) intensity of rivalry among competitors. b) threat of substitute products. c) threat of new entrants. d) bargaining power of suppliers.arrow_forwardA Dia file has been created for you to extend and can be found on Company.dia represents a completed ER schema which, models some of the information implemented in the system, as a starting point for this exercise. Understanding the ER schema for the Company database. To demonstrate that you understand the information represented by the schema, explain using EMPLOYEE, DEPARTMENT, PROJECT and DEPENDENT as examples: attributes, entities and relationships cardinality & participation constraints on relationships You should explain questions a and b using the schema you have been given to more easily explain your answers. Creating and Extending Entity Relationship (EER) Diagrams. To demonstrate you can create entity relationship diagrams extend the ER as described in Company.dia by modelling new requirements as follows: Create subclasses to extend Employee. The employee type may be distinguished further based on the job type (SECRETARY, ENGINEER, MANAGER, and TECHNICIAN) and based…arrow_forward
- Computer programs can be very complex, containing thousands (or millions) of lines of code and performing millions of operations per second. Given this, how can we possibly know that a particular computer program's results are correct? Do some research on this topic then think carefully about your response. Also, explain how YOU would approach testing a large problem. Your answer must be thoughtful and give some insight into why you believe your steps would be helpful when testing a large program.arrow_forwardCould you fix this? My marker has commented, What's missing? The input list is the link below. https://gmierzwinski.github.io/bishops/cs321/resources/CS321_Assignment_1_Input.txt result.put(true, dishwasherSum); result.put(false, sinkSum); return result; }}arrow_forwardPLEG136: Week 5 Portofolio Project Motion to Compelarrow_forward
- B A E H Figure 1 K Questions 1. List the shortest paths between all node pairs. Indicate the number of shortest paths that pass through each edge. Explain how this information helps determine edge betweenness. 2. Compute the edge betweenness for each configuration of DFS. 3. Remove the edge(s) with the highest betweenness and redraw the graph. Recompute the edge betweenness centrality for the new graph. Explain how the network structure changes after removing the edge. 4. Iteratively remove edges until at least two communities form. Provide step-by-step calculations for each removal. Explain how edge betweenness changes dynamically during the process. 5. How many communities do you detect in the final step? Compare the detected communities with the original graph structure. Discuss whether the Girvan- Newman algorithm successfully captures meaningful subgroups. 6. If you were to use degree centrality instead of edge betweenness for community detection, how would the results change?arrow_forwardUnit 1 Assignment 1 – Loops and Methods (25 points) Task: You are working for Kean University and given the task of building an Email Registration System. Your objective is to generate a Kean email ID and temporary password for every new user. The system will prompt for user information and generate corresponding credentials. You will develop a complete Java program that consists of the following modules: Instructions: 1. Main Method: ○ The main method should include a loop (of your choice) that asks for input from five users. For each user, you will prompt for their first name and last name and generate the email and password by calling two separate methods. Example о Enter your first name: Joe Enter your last name: Rowling 2.generateEmail() Method: This method will take the user's first and last name as parameters and return the corresponding Kean University email address. The format of the email is: • First letter of the first name (lowercase) + Full last name (lowercase) +…arrow_forwardI have attached my code, under I want you to show me how to enhance it and make it more cooler and better in graphics with following the instructions.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L