ParseAge Method ^ Text file^ Cemetery Write a program to find the average life span of people
Fantastic news! We've Found the answer you've been seeking!
Question:
ParseAge Method ^
Text file^
Transcribed Image Text:
Cemetery Write a program to find the average life span of people from Little Carter Lane who were buried at St. Mary Magdalene Cemetery, Old Fish Street, City of London during the period January 5, 1813 to July 10, 1853. Below is the start of the cemetery.txt data file (the bold lines represent the actual contents of the file): NAME ST MARY MAGDALENE OLD FISH STREET CITY OF LONDON Burials 5th Jan 1813 - 10th July 1853 John William ALLARDYCE Frederic Alex. ALLARDYCE Philip AMIS Thomas ANDERSON ● ● AGE column 39 11.5 15w 22d BURIAL DATE AGE Note that the AGE field in the file could be in any of the following formats: 17 Mar 1844 2.9 21 Apr 1844 0.17 03 Aug 1848 1 06 Jul 1845 27 15 weeks 22 days Interpretation 39 years 11.5 years RESIDENTIAL ADDRESS Little Knight Ryder Street Little Knight Ryder Street 18 1/2 Knight Rider Street 2, Bennet s Hill 1. A key part of this project is to develop the types (classes) to record information about each internee and to hold the information about all the residents of the cemetery. 2. Create a Tombstone class (and necessary constructor / getter methods) that has instance variables to store the following information: The person s name ● The burialDate (as a String) The person s age (as an integer, more info to follow) ● The address (as a String) 3. Create a Cemetery class with one instance variable, an ArrayList of Tombstone objects. Cemetery s constructor should have a parameter String fileName, which represents a text file containing the information on the interred for this cemetery. The Cemetery class will parse the information in the text file to create and store Tombstone objects. Each line in the file represents one Tombstone object. a. Use a Scanner object to get a single line from the input file at a time, until the end of the file. For each line, make another Scanner object that will tokenize the current line. Be careful when parsing each line! As you can see from the data above, a person can have two or three names - it is suggested that you use Scanner s next method until the input source has a next integer (the day at the beginning of the burial date) to parse the names. Parsing the 3. Create a Cemetery class with one instance variable, an ArrayList of Tombstone objects. Cemetery s constructor should have a parameter String fileName, which represents a text file containing the information on the interred for this cemetery. The Cemetery class will parse the information in the text file to create and store Tombstone objects. Each line in the file represents one Tombstone object. a. Use a Scanner object to get a single line from the input file at a time, until the end of the file. For each line, make another Scanner object that will tokenize the current line. Be careful when parsing each line! As you can see from the data above, a person can have two or three names - it is suggested that you use Scanner s next method until the input source has a next integer (the day at the beginning of the burial date) to parse the names. Parsing the input will require some hard-coding; this is inevitable given the format of the data. Page 3 of 4 b. A method parseAge (String ageString) has been written for you; copy/paste from the text file in the lab folder into your Cemetery class. This method takes the String version of a person s age (e.g. 11.5 or 22d ) from the input file and returns the (rounded) total number of days that person was alive when they were interred. 4. Finally, in a TestCemetery class with a main method, instantiate a Cemetery object, supplying the file name of cemetery.txt to Cemetery s constructor. Next, print the average age, in years rounded to one decimal place (use Math.round()), of everyone that lived on Little Carter Lane . Check with a neighbor (or your teacher, if none available) to make sure you agree on the value that was output. a. Note: the address could include street numbers, commas, etc. (i.e. it won t always be a perfect match). Use String s index of method to check if the desired street is contained anywhere in a Tombstone s address. /** * convert the ageString to a number of days; age can * take a variety of forms in the data file */ public static int parseAge (String ageString) { } if (ageString.contains ( d )) { //age supplied in days ageString = ageString.replaceAll( d , ); return Integer.parseInt (ageString); } int result = 0; boolean done = true; try { result = Integer.parseInt (ageString); } //is the String a whole number of years? catch (Number FormatException n) { done = false; } if (done) //successfully parsed as an int, return value return 365 * result; //ignoring leap years double age Double done = true; try {age Double = Double.parse Double (ageString); } //is the String a floating point number of years? catch (Number FormatException n) { done = false; } if (done) { //successfully parse as a double, String doesn t contain any text return (int) (ageDouble * 365); //ignoring leap years, using 30 for days in a month } = 0; if (ageString.contains ( w )) { //age is supplied in weeks, return appropriately ageString = ageString.replaceAll( w , ); return Integer.parseInt (ageString) 7; } return 0; John William ALLARDYCE Frederic Alex. ALLARDYCE Philip AMIS Thomas ANDERSON Edward ANGEL Sarah ANGELL Sarah ANSELL 17 Mar 1844 2.9 Little Knight Ryder Street 21 Apr 1844 0.17 Little Knight Ryder Street 03 Aug 1848 1 18 1/2 Knight Rider Street 06 Jul 1845 27 2, Bennet s Hill 20 Nov 1842 22 09 Oct 1836 42 31 May 1829 29 Crane Court Lambeth Hill Lambeth Hill High Timber St, Upper Thames St Cemetery Write a program to find the average life span of people from Little Carter Lane who were buried at St. Mary Magdalene Cemetery, Old Fish Street, City of London during the period January 5, 1813 to July 10, 1853. Below is the start of the cemetery.txt data file (the bold lines represent the actual contents of the file): NAME ST MARY MAGDALENE OLD FISH STREET CITY OF LONDON Burials 5th Jan 1813 - 10th July 1853 John William ALLARDYCE Frederic Alex. ALLARDYCE Philip AMIS Thomas ANDERSON ● ● AGE column 39 11.5 15w 22d BURIAL DATE AGE Note that the AGE field in the file could be in any of the following formats: 17 Mar 1844 2.9 21 Apr 1844 0.17 03 Aug 1848 1 06 Jul 1845 27 15 weeks 22 days Interpretation 39 years 11.5 years RESIDENTIAL ADDRESS Little Knight Ryder Street Little Knight Ryder Street 18 1/2 Knight Rider Street 2, Bennet s Hill 1. A key part of this project is to develop the types (classes) to record information about each internee and to hold the information about all the residents of the cemetery. 2. Create a Tombstone class (and necessary constructor / getter methods) that has instance variables to store the following information: The person s name ● The burialDate (as a String) The person s age (as an integer, more info to follow) ● The address (as a String) 3. Create a Cemetery class with one instance variable, an ArrayList of Tombstone objects. Cemetery s constructor should have a parameter String fileName, which represents a text file containing the information on the interred for this cemetery. The Cemetery class will parse the information in the text file to create and store Tombstone objects. Each line in the file represents one Tombstone object. a. Use a Scanner object to get a single line from the input file at a time, until the end of the file. For each line, make another Scanner object that will tokenize the current line. Be careful when parsing each line! As you can see from the data above, a person can have two or three names - it is suggested that you use Scanner s next method until the input source has a next integer (the day at the beginning of the burial date) to parse the names. Parsing the 3. Create a Cemetery class with one instance variable, an ArrayList of Tombstone objects. Cemetery s constructor should have a parameter String fileName, which represents a text file containing the information on the interred for this cemetery. The Cemetery class will parse the information in the text file to create and store Tombstone objects. Each line in the file represents one Tombstone object. a. Use a Scanner object to get a single line from the input file at a time, until the end of the file. For each line, make another Scanner object that will tokenize the current line. Be careful when parsing each line! As you can see from the data above, a person can have two or three names - it is suggested that you use Scanner s next method until the input source has a next integer (the day at the beginning of the burial date) to parse the names. Parsing the input will require some hard-coding; this is inevitable given the format of the data. Page 3 of 4 b. A method parseAge (String ageString) has been written for you; copy/paste from the text file in the lab folder into your Cemetery class. This method takes the String version of a person s age (e.g. 11.5 or 22d ) from the input file and returns the (rounded) total number of days that person was alive when they were interred. 4. Finally, in a TestCemetery class with a main method, instantiate a Cemetery object, supplying the file name of cemetery.txt to Cemetery s constructor. Next, print the average age, in years rounded to one decimal place (use Math.round()), of everyone that lived on Little Carter Lane . Check with a neighbor (or your teacher, if none available) to make sure you agree on the value that was output. a. Note: the address could include street numbers, commas, etc. (i.e. it won t always be a perfect match). Use String s index of method to check if the desired street is contained anywhere in a Tombstone s address. /** * convert the ageString to a number of days; age can * take a variety of forms in the data file */ public static int parseAge (String ageString) { } if (ageString.contains ( d )) { //age supplied in days ageString = ageString.replaceAll( d , ); return Integer.parseInt (ageString); } int result = 0; boolean done = true; try { result = Integer.parseInt (ageString); } //is the String a whole number of years? catch (Number FormatException n) { done = false; } if (done) //successfully parsed as an int, return value return 365 * result; //ignoring leap years double age Double done = true; try {age Double = Double.parse Double (ageString); } //is the String a floating point number of years? catch (Number FormatException n) { done = false; } if (done) { //successfully parse as a double, String doesn t contain any text return (int) (ageDouble * 365); //ignoring leap years, using 30 for days in a month } = 0; if (ageString.contains ( w )) { //age is supplied in weeks, return appropriately ageString = ageString.replaceAll( w , ); return Integer.parseInt (ageString) 7; } return 0; John William ALLARDYCE Frederic Alex. ALLARDYCE Philip AMIS Thomas ANDERSON Edward ANGEL Sarah ANGELL Sarah ANSELL 17 Mar 1844 2.9 Little Knight Ryder Street 21 Apr 1844 0.17 Little Knight Ryder Street 03 Aug 1848 1 18 1/2 Knight Rider Street 06 Jul 1845 27 2, Bennet s Hill 20 Nov 1842 22 09 Oct 1836 42 31 May 1829 29 Crane Court Lambeth Hill Lambeth Hill High Timber St, Upper Thames St
Expert Answer:
Answer rating: 100% (QA)
Find below the well explainedusing comments Java code that fulfills all the requirements of the problem statement I am assuming that the data in the text file are separated by a space And your given t... View the full answer
Related Book For
Principles of Communications Systems, Modulation and Noise
ISBN: 978-8126556793
7th edition
Authors: Rodger E. Ziemer, William H. Tranter
Posted Date:
Students also viewed these programming questions
-
Write a PYTHON program that reads a text file and counts how many occurrences of each character are there in the text. The user may ask the program to ignore some characters and those to be ignored...
-
A text analyst wants to analyze a text file (refer to File.txt on Moodle). She wants to find out the total number of sentences in the text file. She would also like to know if there are acronyms in...
-
The FL Crime data file on the text CD has data for the 67 counties in Florida on y = crime rate: Annual number of crimes in county per 1000 population x1 = education: Percentage of adults in county...
-
Solve the linear equation with the x-intercept method. Check your answer. Approximate the solution to the nearest thousandth whenever appropriate. -1-x = = 0
-
Many opportunities await those who troll the big job boards, the free-agent sites, the reverse auction services, and the niche sites for specialized jobs and skills. Presented below are diverse...
-
The inner and outer dimensions of a coaxial copper transmission line are 2 and 7 mm, respectively. Both conductors have thicknesses much greater than . The dielectric is lossless and the operating...
-
Identify the three types of injunctions. What is the purpose of each type of injunction?
-
Selected accounts for Winslow Inc. as at December 31, 2014, are as follows: Instructions Prepare closing entries for Winslow Inc. on December 31, 2014. $ 5,000 22,000 Sales Returns and Allowances...
-
Briefly discuss the impact of Artificial Intelligence (AI) on Marketing Research. Identify two benefits and two challenges. Name an example of an AI tool or technology being used for marketing...
-
In a sample of 539 households from a certain Midwestern city, it was found that 133 of these households owned at least one firearm. Give a 99% confidence interval for the percentage of families in...
-
A- Palermo Corporation acquired an 80% interest in Steel Corporation at a cost equal to 80% of the book value of Steel's net assets several years ago. At the time of purchase, the fair value and book...
-
Ch. 21 - Final Exam > Pg. 4- Course Final Exam 8 of 100 EBB GET $25 X I LE For some reason, the seller of a home at 123 Mulberry Lane decided not to close on a sale transaction on closing day. The...
-
Whats is 8800 kg/m3 and 880 kg/m3 in kg/mm3?how is the conversion done?
-
Assume you take a loan of $355,000. The loan is for 10 years, and the annual interest rate offered by bank is 10.75 per cent. If the cash repayment frequency is on monthly basis and interest payment...
-
Ch. 21 - Final Exam > Pg. 4 - Course Final Exam GET $25 ibri Real Estate X 6 of 100 Roger has been farming his land in Florida for nearly 30 years. His principal crops are corn and soybeans. He also...
-
Using the comparison calculator between a Roth IRA and a regular IRA found at a web based calculator decide whether an individual with the following data is better off with a regular IRA or a Roth...
-
The village of Briarcliff operates on a calendar-year basis. Because of cash flow imbalances in the General Fund, the village needs to borrow cash during the year. Also, at various times during the...
-
Quality Chicken grows and processes chickens. Each chicken is disassembled into five main parts. Information pertaining to production in July 2012 is: Joint cost of production in July 2012 was $50. A...
-
A second-order Butter worth filter has 3-dB bandwidth of 500 Hz. Determine the unit impulse response of the filter and use it to compute the noise-equivalent bandwidth of the filter. Check your...
-
Find the impulse response of an ideal high pass filter with the frequency response function -2 fto p() %3D | 1- 2W
-
Given a joint pdf defined as Find the following:(a) f X (x); (b) f Y (y);? (c) E[X], E[Y], E[X 2 ], E[Y 2 ], ? 2 X , ? 2 Y , (d) E[XY]; (e) u XY . 1, 0 < x < 1, 0
-
Consider the monthly simple excess returns of 10 U.S. stocks from January 1990 to December 2003 for 168 observations. The 3-month Treasury bill rate on the secondary market is used to compute the...
-
Which provides stronger evidence against H0: a P-value of 0.05 or a P-value of 0.50?
-
A test is made of H0 : = 6 versus H1: 6. a. The test statistic is z = 0.75. Find and interpret the P-value. b. The test statistic is z = 2.20. Find and interpret the P-value. c. Which provides...
Study smarter with the SolutionInn App