Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ParseAge Method ^ Text file^ Cemetery Write a program to find the average life span of people from Little Carter Lane who were buried at

image

image

imageParseAge Method ^

imageText file^

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

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles of Communications Systems, Modulation and Noise

Authors: Rodger E. Ziemer, William H. Tranter

7th edition

978-1-118-0789, 1118078918, 978-8126556793

More Books

Students also viewed these Programming questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago