Question
Focus of the Assignment on Programming Techniques This assignment will focus on creating a immutable class, where once an object has been created the data
Focus of the Assignment on Programming Techniques This assignment will focus on creating a immutable class, where once an object has been created the data in the object cannot be altered, only accessed. input from a large text data file where each line of will be a single record of data. The data from each record will be used to make a CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 2 II. Data Description of the Data in the File oncampuscrime.txt Each line of data is the file is one unique record containing information about serious crimes against persons occurring in one year (2014, 2015 or 2016) on a campus of an institution of higher education in the United States. There are over 30,000 records in the file. Each record will consist of the following data values, each item of data separated by a space: the year - integer consisting of 2014, 2015 or 2016 the state - string consisting of the USPS abbreviation for a state institution or campus type - integer from 1 to 9 inclusive (equivalence list given below) number of male students - positive integer number of female students - positive integer number of murders - integer; -1 indicates data not available, otherwise the data is >= zero umber of negligent homicides - integer; -1 indicates data not available, otherwise the data is >= zero number of rapes - integer; -1 indicates data not available, otherwise the data is >= zero number of aggravated assaults- integer; -1 indicates data not available, otherwise the data is >= zero Example of Data from the File oncampuscrime.txt 2016 MA 2 15290 14618 0 0 1 0 2014 FL 3 418 538 0 0 0 0 2015 GA 4 432 1131 1 1 1 1 2014 MD 1 1803 2515 0 0 0 0 2015 MN 9 0 103 0 0 0 0 2016 CT 2 695 1170 0 0 7 2 List of USPS State Abbreviations AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 3 List of Institution or Campus Types 1 public, 4 year or above 2 private nonprofit, 4 year or above 3 private for profit, 4 year or above 4 public, 2 year 5 private nonprofit, 2 year 6 private for profit, 2 year 7 public, less than 2 year 8 private nonprofit, less than 2 year 9 private for profit, less than 2 year III. Programming Assignment Steps 1. Create a new NetBeans Java application project and name it pa7_your-id. As part of the project, NetBeans will create package pa7_your-id. In the package, files Pa7_ your-id.java will be created. 2. Create a class to serve as a crime data type. To do this, create an immutable class (a class without setters, only private fields, constructors and getters) to hold one campus crime record for one year, i. e. to hold one line of data from the file as individual data elements (not as a single string). (a) Right click on the package pa7_your-id and select New, Java Class. Name the class appropriately. This class will be referred to in this document as the crime class. (b) Suggestion: Include methods to return summary information. Example, a method to return total students and another to return total crimes. 3. Create a data structure to hold all the data in crime class objects. Create an ArrayList reference variable and ArrayList object to hold objects of the crime class type. 4. On program start, load the crime data from the file, storing each line of data in a crime class object and placing all of the crime class objects in the ArrayList. (a) For each line of data in the file, create an object of the crime class. (b) Add each crime class object created to the ArrayList. CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 4 5. You will need 5 user inputs. (a) Necessary input that will be used to define the data request include user entries for: i. total or percent crime summaries selection. ii. type of crime, including an All option. iii. year selection, including an All option. iv. campus / institution type, including an All option. v. state abbreviation, including an All option. Tip: Check each input and, if it is an invalid value, set it to the All option. Tip: An array of state abbreviations can be easier to load and check the user entry for validity than an ArrayList of state abbreviations. 6. When the user input is complete, the user entries made can then be used to determine the report. This could be done exclusively in a very convoluted set of nested if-else statements, but, while some if-else work is required, there is a better way that reduces complexity. For example: (a) Step 1: Isolate the crime objects of the desired states. i. Make a second ArrayList reference variable. ii. If the state required is all states, assign the second ArrayList reference variable to refer to the original ArrayList of crime class objects. iii. If the state is a specific state, A. Create a second ArrayList object for the second ArrayList reference variable to reference. B. Traverse the original ArrayList and add each crime object with the right state to the second ArrayList. (b) Step 2: Isolate the crime objects of the desired campus / institution type. i. Make a third ArrayList reference variable. ii. If the campus type required is all campus types, assign the third ArrayList reference variable to refer to the second ArrayList of crime class objects. iii. If the campus type is a specific campus type, A. Create a third ArrayList object for the third ArrayList reference variable to reference. B. Traverse the second ArrayList and add each crime object with the right campus type to the third ArrayList. CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 5 (c) Step 3: Isolate the crime objects of the desired crime type. i. Make a fourth ArrayList reference variable. ii. If the crime type required is all crime types, assign the fourth ArrayList reference variable to refer to the third ArrayList of crime class objects. iii. If the crime is a specific crime, A. Create a fourth ArrayList object for the fourth ArrayList reference variable to reference. B. Traverse the third ArrayList and add each crime object with the right crime type to the fourth ArrayList. (d) Step 4: Now traverse the fourth ArrayList and total up all male students, all female students and all of the selected crime type (which will require if / if-else / nested if logic). 7. Finally, output the report (which may require additional if / if-else / nested if logic). Tip: Dont divide by Zero!!!! Example Runs (User input in Red): Run Example #1: Enter Total or Percent: Total Enter Crime Type (Murder, NegHom, Rape, AgAslt, All): All Enter year (2014, 2015, 2016, All): All 0All, 1Pub4yr, 2priNoProf, 3PriProf4yr, 4Pub2yr, 5PriNoProf2yr, 6PriPro2yr, 7Pub<2yr, 8PriNoPro<2yr, 9priProf<2yr Enter Campus Type Number: 0 AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY Enter State Abbreviation: All Male Students: 98814087 Female Students: 124403640 Total all crimes: 22491 CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 6 Run Example #2: Enter Total or Percent: Percent Enter Crime Type (Murder, NegHom, Rape, AgAslt, All): All Enter year (2014, 2015, 2016, All): All 0All, 1Pub4yr, 2priNoProf, 3PriProf4yr, 4Pub2yr, 5PriNoProf2yr, 6PriPro2yr, 7Pub<2yr, 8PriNoPro<2yr, 9priProf<2yr Enter Campus Type Number: 0 AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY Enter State Abbreviation: All Male Students: 98814087 Female Students: 124403640 1 crime for every 9924 students Run Example #3: Enter Total or Percent: Total Enter Crime Type (Murder, NegHom, Rape, AgAslt, All): AgAslt Enter year (2014, 2015, 2016, All): 2015 0All, 1Pub4yr, 2priNoProf, 3PriProf4yr, 4Pub2yr, 5PriNoProf2yr, 6PriPro2yr, 7Pub<2yr, 8PriNoPro<2yr, 9priProf<2yr Enter Campus Type Number: 1 AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY Enter State Abbreviation: LA Male Students: 111770 Female Students: 170653 Total agrv assult: 25 CMPS 260 Spring 2018 Programming Assignment #7 (2018-04-20) 7 Run Example #4: Enter Total or Percent: Percent Enter Crime Type (Murder, NegHom, Rape, AgAslt, All): Murder Enter year (2014, 2015, 2016, All): 2016 0All, 1Pub4yr, 2priNoProf, 3PriProf4yr, 4Pub2yr, 5PriNoProf2yr, 6PriPro2yr, 7Pub<2yr, 8PriNoPro<2yr, 9priProf<2yr Enter Campus Type Number: 1 AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY Enter State Abbreviation: TX Male Students: 1585503 Female Students: 1800353 1 murder for every 1692928 students
Step by Step Solution
There are 3 Steps involved in it
Step: 1

Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2

Step: 3

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