CSC 1051 – Project 11: Processing the Titanic Data Project due Wednesday December 4, 2013 Preparation: Review the textbook example of a DVD database. Use this program as a model to create a database to store data about passengers of the Titanic. File links: •
•
•
•
www.csc.villanova.edu/~map/1051/Chap08/DVD.java www.csc.villanova.edu/~map/1051/Chap08/DVDCollection.java www.csc.villanova.edu/~map/1051/Chap08/Movies.java Dataset: http://www.csc.villanova.edu/~map/1051/f13/examples/titanic.txt Classes: You should create the following classes: 1) Passenger class: Represents a passenger of the Titanic, with attributes: • status (an integer: 1, 2, 3, or 4, representing 1st, 2nd, 3rd class or crew • child (a boolean: true = child, false = adult) • sex (a char: ‘m’ or ‘f’) • survivor (a boolean: true/false indicating whether this passenger survived) The constructor and toString() methods should work in a way similar to the DVD class. 2) PassengerData class: Represents a collection of Titanic passenger records, similar to the DVDCollection class. Attributes should include: • collection (an array of Passenger) • count (an int representing the size of the database) • numSurvivors (an int representing the number of survivors) The constructor and other methods of this class should parallel the ones of the DVDCollection class. 3) TitanicTester class: This is a driver class, similar to Movies class. Use it to test the other classes: public class TitanicTester
{
public static void main(String[] args)
{
TitanicData titanic = new TitanicData();
titanic.addPassenger
titanic.addPassenger
titanic.addPassenger
titanic.addPassenger
titanic.addPassenger
(4,
(3,
(1,
(2,
(3,
false, 'm', false);
false, 'f', false);
true, 'm', true);
false, 'm', false);
true, 'f', true);
System.out.println(titanic);
titanic.addPassenger (3, true, 'm', false);
titanic.addPassenger (1, true, 'f', false);
titanic.addPassenger (3, false, 'f', false);
System.out.println(titanic);
}
} CSC1051 Data Structures and Algorithms I
Dr. Papalaskari
Fall 2013
Before proceeding, be sure that TitanicTester runs correctly without any modifications (modify your Passenger and PassengerData classes, if necessary). Include a run of TitanicTester along with the sample runs in your report. Titanic class: processing real data 4) Titanic class: Once your program is working with the driver TitanicTester, above, you are ready to create a new driver, the Titanic class, to access and process a data file with the actual survival data from the Titanic. The dataset we will be using is a text file containing information about all the passengers, one per line. It looks like this: … 2
1
4
3
1
… false male
true female
false male
false male
false male
true
true
true
false
true
Since there were more than 2000 passengers, it is a big file! Your program should process this information and compute statistics for the dataset. At the very minimum, you should display the number of survivors. Extra credit is available for computing more interesting statistics. Hints: • Use a technique similar to Lab11e, where a data file was processed one line at a time, using a second Scanner to scan the words from each line. • Note that the data are not exactly in the format expected by your Passenger constructor. Use nextInt() to obtain the status; nextBoolean() to obtain the values for child and survivor; and extract the first character from the string obtained via next() for the sex. Testing Be sure to test your program well. You can verify your answers by searching online for information about the Titanic disaster – there is a lot of information available from the many museum exhibits and extensive studies of the Titanic tragedy. UML class diagram Include a UML class diagram that shows all your classes and their dependencies. Style and Documentation Be sure to review your code to ensure that all your classes have appropriate comments and that the code is well indented. In addition to working well, programs should adhere to the general style and documentation guidelines used in the textbook. Report What to include: 1. Source code for all your classes 2. Test runs of Titanic and TitanicTester. 3. UML class diagram for your classes CSC1051 Data Structures and Algorithms I
Dr. Papalaskari
Fall 2013
4. A reflection about this project. How long did it take? Was it easier/harder than you expected? How did you approach it? What would you do differently if you were starting over or had more time? Include any other comments and observations here. CSC1051 Data Structures and Algorithms I
Dr. Papalaskari
Fall 2013
© Copyright 2026 Paperzz