To create an educational webpage for this Java programming exercise, the content can be structured as follows: --- ### Java Programming Exercise: Tombstone and Cemetery Classes #### Objective Learn how to create and manage collections of objects in Java by implementing classes that handle personal information and store it in a structured manner. #### Task Overview 1. **Create a Tombstone Class** - Develop a `Tombstone` class with instance variables to store: - **name**: The name of the person. - **burialDate**: The date of burial. - **age**: The age of the person (use an integer). - **address**: The address related to the person. - Implement appropriate constructor and getter methods to initialize and access these variables. 2. **Open the Cemetery Class** - **Purpose**: Manage a collection of `Tombstone` objects. - **Instance Variable**: An `ArrayList` that stores `Tombstone` objects. - **Constructor Details**: - Accepts a `String fileName` as a parameter, representing a text file with burial information. - Initializes the internal `ArrayList` to organize the `Tombstone` objects. 3. **Parsing and Storing Data** - **Process the File**: - Each line of the input file represents a single `Tombstone` object. - **Implementation Steps**: - Use a `Scanner` object to read the entire file. - Employ another `Scanner` object to retrieve and process each line separately (utilize methods like `hasNextLine()` and `nextLine()`). - **Parsing Tips**: - Handle multiple names carefully; people may have two or three names. Use `Scanner's next()` method until an integer, which indicates the start of a burial date, is found. - **Constructor Functionality**: - Parse and extract data such as name, burial date, age, and address from each line to create `Tombstone` objects. - Implement a method named `parseAge(String ageString)` to appropriately parse and convert age information. --- This exercise guides students through implementing classes in Java, focusing on reading and interpreting structured data files. It provides practical experience in object-oriented programming, file handling, and data parsing techniques. 2. **Open the Cemetery class.** Create one instance variable, an ArrayList of Tombstone objects. The Cemetery's constructor should have a parameter `String fileName`, which represents a text file containing the information on the interred for this cemetery. Don’t forget to initialize the PIV as a new ArrayList. The Cemetery constructor 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 scan in the **entire** input file. Use another Scanner object to get a single line (use `hasNextLine()` and `nextLine()`) from the input file at a time, until the end of the file. 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. b. This constructor will be parsing the name, burial date, age, and address of each person in the file. A method `parseAge(String ageString)` has been written for you, that will take the String version of a person's age (e.g. "11.5" or "22d") from the input file and return the (rounded) total number of **days** that person was alive when they were interred.
To create an educational webpage for this Java programming exercise, the content can be structured as follows: --- ### Java Programming Exercise: Tombstone and Cemetery Classes #### Objective Learn how to create and manage collections of objects in Java by implementing classes that handle personal information and store it in a structured manner. #### Task Overview 1. **Create a Tombstone Class** - Develop a `Tombstone` class with instance variables to store: - **name**: The name of the person. - **burialDate**: The date of burial. - **age**: The age of the person (use an integer). - **address**: The address related to the person. - Implement appropriate constructor and getter methods to initialize and access these variables. 2. **Open the Cemetery Class** - **Purpose**: Manage a collection of `Tombstone` objects. - **Instance Variable**: An `ArrayList` that stores `Tombstone` objects. - **Constructor Details**: - Accepts a `String fileName` as a parameter, representing a text file with burial information. - Initializes the internal `ArrayList` to organize the `Tombstone` objects. 3. **Parsing and Storing Data** - **Process the File**: - Each line of the input file represents a single `Tombstone` object. - **Implementation Steps**: - Use a `Scanner` object to read the entire file. - Employ another `Scanner` object to retrieve and process each line separately (utilize methods like `hasNextLine()` and `nextLine()`). - **Parsing Tips**: - Handle multiple names carefully; people may have two or three names. Use `Scanner's next()` method until an integer, which indicates the start of a burial date, is found. - **Constructor Functionality**: - Parse and extract data such as name, burial date, age, and address from each line to create `Tombstone` objects. - Implement a method named `parseAge(String ageString)` to appropriately parse and convert age information. --- This exercise guides students through implementing classes in Java, focusing on reading and interpreting structured data files. It provides practical experience in object-oriented programming, file handling, and data parsing techniques. 2. **Open the Cemetery class.** Create one instance variable, an ArrayList of Tombstone objects. The Cemetery's constructor should have a parameter `String fileName`, which represents a text file containing the information on the interred for this cemetery. Don’t forget to initialize the PIV as a new ArrayList. The Cemetery constructor 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 scan in the **entire** input file. Use another Scanner object to get a single line (use `hasNextLine()` and `nextLine()`) from the input file at a time, until the end of the file. 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. b. This constructor will be parsing the name, burial date, age, and address of each person in the file. A method `parseAge(String ageString)` has been written for you, that will take the String version of a person's age (e.g. "11.5" or "22d") from the input file and return the (rounded) total number of **days** that person was alive when they were interred.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
how would you do this in a simple way? this is a non graded practice lab
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
Unlock instant AI solutions
Tap the button
to generate a solution
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education