Description
Assignment Purpose The purpose of this assignment is to put into practice the main principles of object oriented programming that you have learned so far, in addition to using the ArrayList collections class and file input. There will be three closely related classes, plus class Main, in which the concepts of inheritance and composition will be featured. Assignment Overview The data for the project is taken from health data survey data organized by city that was downloaded from the data.gov site. The project you will create will require the creation of a class to hold a record of data about some aspect of a health measure from a sample of a portion of a city. That class will be used as the type of a generic ArrayList. Another class will hold data about a single city, managing the loading of data into an object of the ArrayList type and providing methods to analyze the data stored in the ArrayList. The city class will also inherit from a State class (provided). When run, the user will input the name of a data file about a city, the file named will be loaded as part of the constructor of the city class, most of the data being stored in the ArrayList composed within the city class. Once loaded, a file of measures (basically health survey categories) will be loaded and displayed to the user, who will then pick a measure which is then passed to the city class object for analysis by method calls. These analysis methods will traverse the ArrayList to find and accumulate the necessary data. Getting Started Download, extract, rename and open the provided Intellij project. (a) Download the provided zip file “pa07.zip” and extract the Intellij project folder within (“pa07”). Windows user are reminded to copy the project folder out of the zip and paste it elsewhere. (b) Once the folder (“pa07”) has been extracted, right click on the folder and rename it “pa07_user-id”. (c) The project can now be opened in Intellij. When opened, notice that there are two classes. One class is in the file “State.java”, which will be used later. The other class is the usual Main class. CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 2 Understanding the Data 1. Inside the Intellij project folder there are 7 data files. Six of these are city data files and one is a list of the measurements from the health survey. The files are organized as follows. 2. File “questions.txt” (a) This file is the list of measurements from the health survey. There is one measurement on each line of the file. These are the measures that will be presented as a menu for the user’s choice. Here is an example of the first and last lines in the file. Current lack of health insurance among adults aged 18–64 Years Arthritis among adults aged >=18 Years … Sleeping less than 7 hours among adults aged >=18 Years All teeth lost among adults aged >=65 Years (b) These measures are not stored in the city data files, where they are instead referenced by an integer code, known as a key. In a city data file, the measure key 1 refers to the first measure in the measures file “Current lack of health insurance among adults aged 18–64 Years”, the measure key 2 refers to the second measure in the measures file “Arthritis among adults aged >=18 Years”, etc. As there are 28 measures in the file, 28 is the key for “All teeth lost among adults aged >=65 Years”. 3. City Data Files (a) For this assignment, the city data files will be limited to health survey data of six Louisiana cities. (b) “br.txt” contains Baton Rouge data, “ken.txt” contains Kenner data, “laf.txt” contains Lafayette data, “lc.txt” contains Lake Charles data, “nola.txt” contains New Orleans data and “sp.txt” contains Shreveport data. (c) Data in these city files is organized as follows: i. Line one contains the name of the state of the city. ii. Line two contains the abbreviation of the state of the city. iii. Line three contains the name of the city. iv. Lines four and all the lines that follow are organized in fields of numbers, each separated by a single space, essentially making columns of data in the file. These fields are: A. field 1: sample size int; the number of people in the area sampled B. field 2: percentage double; the percent result of the survey; stored in the form ##.# (example 50.2 is 50.2 percent) C. field 3: lower confidence double; the lower bounds of confidence in the percentage; stored in the form ##.# (example 50.2 is 50.2 percent) D. field 4: upper confidence double; the upper bounds of confidence in the percentage; stored in the form ##.# (example 50.2 is 50.2 percent) E. field 5: latitude central latitude of the sample area F. field 6: longitude central longitude of the sample area G. field 7: measure key the code (key) of the measure of the survey results CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 3 (d) Example of data of in a city file: Louisiana LA Lafayette 3351 22.4 18.9 26.3 30.2248618566 -92.0194019578 1 2257 22.1 18.7 25.5 30.2199540086 -92.0033645168 1 2503 10.7 8.1 14 30.2153844022 -92.0340798419 1 … 1026 68.2 63.9 72 30.1527301524 -91.9851212329 12 686 65.7 61.4 69.6 30.1833232633 -91.9958805141 12 5287 69.8 65.6 73.4 30.1985462427 -92.028270898 12 … 4064 13.4 7.5 20.5 30.1965012966 -92.0818885855 28 239 14.8 9 22 30.1750365398 -92.0865055008 28 6329 14.2 9.9 19.6 30.20913162 -92.0206656257 28 Make a class to hold one line of survey data for a city. 1. The survey data is found on lines four to a city file’s end. 2. This will be an immutable class. This means it has no setter (mutator) methods, only fields, constructors and getter (accessor) methods. 3. Create the class and file in the project as usual, then (a) add a private field for each of the seven fields on line four (and beyond) of a city file as described in “Understanding the Data” 3.c.iv. (b) Add a constructor that accepts the values for the fields and assigns valid values. The limits are as follows. i. sample size must be 0 or greater ii. percentage, lower confidence and upper confidence must be in the range [0, 100], i. e. 0 to 100 inclusive iii. latitude must be in the range [25,50], i. e. 25 degrees north to 50 degrees north to belong to a city in the “lower 48” states iv. longitude must be in the range [-65,-130], i. e. -65 degrees to -130 degrees to belong to a city in the “lower 48” states; negative longitudes indicate west of the prime meridian v. measure key must be a value in the range [1,28], i. e. 1 to 28 inclusive (c) create a getter (accessor) for each of the private data fields (d) as a parametrized constructor exists, a default constructor must be created, even if it is empty of any code CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 4 Make a City Class 1. This too will be an immutable class. This means it has no setter (mutator) methods, only fields, constructors and getter (accessor) methods. 2. Create the class in the project as usual, then (a) inherit class State (b) add a private field for the city name and add a getter (accessor) method (c) add a private ArrayList field (d) create a default constructor (e) create a parametrized constructor i. this constructor receives a single parameter of type Scanner that references an existing Scanner class object that references a city file ii. using the Scanner class object, read in the name of the state, state abbreviation, and city name, then loop through the rest of the file reading in the city survey data A. for every line of survey data read, create an object of the survey data class and store it in the ArrayList field (f) create methods to i. return the total population of the city (hint: arbitrarily select a measure to sum) ii. receive a measure key and return the average percent (mean of the survey results) for that measure iii. receive a measure key and return the average upper confidence (mean of the survey upper confidence) for that measure iv. receive a measure key and return the average lower confidence (mean of the survey upper confidence) for that measure v. return the average latitude vi. return the average longitude Create the User Interface 1. The user must input the file to use. 2. Create a Scanner class object and pass it to the city class constructor so the correct city file can be read. 3. Call methods to show the state, state abbreviation and city name. 4. Create a Scanner class object and use it to read “questions.txt” (the measures file). Tip: Load the measures into an ArrayList for repeated use. 5. Display the measures as a menu and the average percentage and confidence results from the user’s selection. 6. Continue to prompt the user for a measure until the user decides to exit. CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 5 Example Run (user input in red) Enter city file path: laf.txt Lafayette Louisiana LA population: 120623 avg lat: 30.20491668384118 avg long: -92.03661815420294 1: Current lack of health insurance among adults aged 18–64 Years 2: Arthritis among adults aged >=18 Years 3: Binge drinking among adults aged >=18 Years 4: High blood pressure among adults aged >=18 Years 5: Taking medicine for high blood pressure control among adults aged >=18 Years with high blood pressure 6: Stroke among adults aged >=18 Years 7: Cancer (excluding skin cancer) among adults aged >=18 Years 8: Current asthma among adults aged >=18 Years 9: Coronary heart disease among adults aged >=18 Years 10: Visits to doctor for routine checkup within the past Year among adults aged >=18 Years 11: Cholesterol screening among adults aged >=18 Years 12: Fecal occult blood test sigmoidoscopy or colonoscopy among adults aged 50–75 Years 13: Chronic obstructive pulmonary disease among adults aged >=18 Years 14: Older adult men aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever Colorectal cancer screening 15: Older adult women aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever Colorectal cancer screening and Mammogram past 2 Years 16: Current smoking among adults aged >=18 Years 17: Visits to dentist or dental clinic among adults aged >=18 Years 18: Diagnosed diabetes among adults aged >=18 Years 19: High cholesterol among adults aged >=18 Years who have been screened in the past 5 Years 20: Chronic kidney disease among adults aged >=18 Years 21: No leisure-time physical activity among adults aged >=18 Years 22: Mammography use among women aged 50–74 Years 23: Mental health not good for >=14 days among adults aged >=18 Years 24: Obesity among adults aged >=18 Years 25: Papanicolaou smear use among adult women aged 21–65 Years 26: Physical health not good for >=14 days among adults aged >=18 Years 27: Sleeping less than 7 hours among adults aged >=18 Years 28: All teeth lost among adults aged >=65 Years Measure? 13 CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 6 avg value: 7.33% avg lower: 6.31% avg upper: 8.43% Continue? (Y/N) y 1: Current lack of health insurance among adults aged 18–64 Years 2: Arthritis among adults aged >=18 Years 3: Binge drinking among adults aged >=18 Years 4: High blood pressure among adults aged >=18 Years 5: Taking medicine for high blood pressure control among adults aged >=18 Years with high blood pressure 6: Stroke among adults aged >=18 Years 7: Cancer (excluding skin cancer) among adults aged >=18 Years 8: Current asthma among adults aged >=18 Years 9: Coronary heart disease among adults aged >=18 Years 10: Visits to doctor for routine checkup within the past Year among adults aged >=18 Years 11: Cholesterol screening among adults aged >=18 Years 12: Fecal occult blood test sigmoidoscopy or colonoscopy among adults aged 50–75 Years 13: Chronic obstructive pulmonary disease among adults aged >=18 Years 14: Older adult men aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever Colorectal cancer screening 15: Older adult women aged >=65 Years who are up to date on a core set of clinical preventive services: Flu shot past Year PPV shot ever Colorectal cancer screening and Mammogram past 2 Years 16: Current smoking among adults aged >=18 Years 17: Visits to dentist or dental clinic among adults aged >=18 Years 18: Diagnosed diabetes among adults aged >=18 Years 19: High cholesterol among adults aged >=18 Years who have been screened in the past 5 Years 20: Chronic kidney disease among adults aged >=18 Years 21: No leisure-time physical activity among adults aged >=18 Years 22: Mammography use among women aged 50–74 Years 23: Mental health not good for >=14 days among adults aged >=18 Years 24: Obesity among adults aged >=18 Years 25: Papanicolaou smear use among adult women aged 21–65 Years 26: Physical health not good for >=14 days among adults aged >=18 Years 27: Sleeping less than 7 hours among adults aged >=18 Years 28: All teeth lost among adults aged >=65 Years Measure? 28 avg value: 17.96% avg lower: 12.49% avg upper: 24.40% Continue? (Y/N) n CMPS 260 Spring 2019 Programming Assignment #7 (2019.04.03a) 7 Requirements • For input from a file, Scanner object declarations must be made in a try-with-resources. • There is no user input or output in the state, city or survey data classes. Additional Requirements (a)If there is input, reference variables and instance objects of class java.util.Scanner must be used to read the input from the user or from files. Prompts for any user input must be clear and relevant. (b)Output to the user must include appropriate labels. (c)Identifiers must be descriptive, i. e. must self document. The only exception granted is in the case of a “for variable”, that is a variable created as a simple counter as in the control variable in a “for” loop statement. (d)Indention of all code blocks (compound statements, anything in braces), including single statements following selection or while statements, is required. (e)The main “.java” file [the one with the method public static void main(String[] args)] of your Intellij projects must contain this minimal documentation as the first lines of the file (i. e. above the package statement): // Your Name // Your ID // CMPS 260 // Programming Assignment : # // Due Date : // Program Description: (a brief description of actions of your code) // Certificate of Authenticity: (Choose one of the two following forms:) // I certify that the code of this project, other than that that was generated by Intellij or // provided by the instructor, is entirely my own work. {or} // I certify that the code of this project, other than that that was generated by Intellij or // provided by the instructor, is entirely my own work, but I received some assistance from // {name}. Follow this with a description of the type of assistance. (For example, if you consulted // a book, and your solution incorporates ideas found in the book, give appropriate credit; that is, // include a bibliographical reference.) Note: You do not have to list the text, the author of the // course text or the instructors examples. Submitting In Intellij, select File, Save All, then select File, Export to Zip File and click OK to save the Zip archive file. Finally, upload the zip archive file to Moodle. Helpful Hint: Keep a backup copy of your project folder on a Google Drive, a Drop Box Account, a USB memory device, etc., or even on Moodle! Finally, once you turn in your final version, create a copy before the due date and do not change this copy in any way. This final copy can be consulted if there is an upload disaster, but only if the “.java” files have not been changed in any way after the due date.