Question
Java!! Could someone help me with this problem? Please 1st download the text file presidents.txt at https://uploadfiles.io/wtas9 Data File Each line in this
Java!! Could someone help me with this problem?
Please 1st download the text file " presidents.txt " at https://uploadfiles.io/wtas9
Data File
Each line in this file has four pieces of information, separated by tabs.
Last name \t First name \t Date took office \t Date left office
The basic task for this lab is to read through the data file, and create an output file which will contain sentences with the information read from the data file. For example, the first line of the file is:
Lincoln\tAbraham\t3/4/1861\t4/15/1865
The four pieces of information are:
Lincoln
Abraham
3/4/1861
4/15/1865
The output sentence for this data is:
Abraham Lincoln was president from 3/4/1861 to 4/15/1865.
Please note:
There is a period at the end of the sentence. There will be a functionality deduction if the period is not present in the output files.
You will probably find it easier if you read the data from the file line by line. You can use Scanner or BufferedReader to read in a line at a time.
The String.split method can prove very helpful here.
Output File(s)
There are two options that come to mind:
A function that takes a single string parameter, that is, the input data, and returns the sentence generated using that data. The caller will have to take that return value and write it to the output file.
A function that takes two parameters: the input data, and the stream object for output, a Writer. The function can generate the sentence and immediately write it to the file object. Notice, this suggests that the second parameter is the stream object, rather than the filename. So, after you open the output file for writing, you get the stream object, probably wrapped in a filter object to make it easier to use. Pass this stream object to the function. That way the output file only needs to be opened once.
[hidden hint]: Notice that these suggestions both treat the data for a president as a single object, the line from the input file, rather than as four separate pieces of data. The method can handle the separation of the input line into the four pieces of data.
Minimal Version
For the minimal version, you only need to create a single file. The output file is same_order.txt. The sentences in the output file shall be in the order that the data appears in the data file, presidents.txt. (Can you figure out what that order is? Participation points)
Here is some pseudo-code for creating same_order.txt:
open the input file open the output file for each line in the input file call your function to write out the sentence close the input file close the output file
This pseudo-code will work for either version of the helper function. You just have to keep in mind how much work is going on in your helper function. (Actually, if you're only doing the minimal version, there is no advantage to creating the helper function.)
--------------Sample output-----------------
Here is what the beginning of the output file same_order.txt should look like:
Abraham Lincoln was president from 3/4/1861 to 4/15/1865. Andrew Jackson was president from 3/4/1829 to 3/4/1837. Andrew Johnson was president from 4/15/1865 to 3/4/1869.
Please note: The name of eighth POTUS is Martin Van Buren. [questions to ponder: POTUS? Why should is this fact of importance to the assignment?]
Standard Version
For the standard version, you need to create two files. The two output files are: same_order.txt and last_name.txt. The first, same_order.txt, is the same as the one created for the minimal version, with the sentences in the same order as the data in the presidents.txt file. In the second file, last_name.txt, the sentences shall be ordered by name, Last first. In those cases where the last names are the same, the Johnsons, the Adamses, and the Bushes, sort by first name. If you're really concerned, the two discontiguous terms by Grover Cleveland can be ordered by date.
To accomplish this, read the whole file into the program, and rearrange the data within your program. (Hint: java.util.Arrays.sort)
----------------Sample output------------
Here is what the beginning of the output file last_name.txt should look like:
John Adams was president from 3/4/1797 to 3/4/1801. John Quincy Adams was president from 3/4/1825 to 3/4/1829. Chester A Arthur was president from 9/19/1881 to 3/4/1885.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started