Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StopFriskReportAnalyzer
- {
- /**
- * Given an array of stop and frisk reports,
- * returns the average age of all the women who were stopped
- * in outer boroughs during AFSE's school hours (9:00 AM to
- * 3:20 PM)
- *
- * @param data An array of StopFriskReports
- * @return the average age of all women stopped in outer
- * boroughs during AFSE's school hours
- */
- public static double avgAgeFOuterSchool(StopFriskReport[] reports)
- {
- double sumOfAges = 0;
- int cOfReports = 0;
- for(int i = 0; i < reports.length; i++){
- StopFriskReport rep = reports[i];
- String gender = rep.getGender();
- boolean isFemale = gender.equals("F");
- boolean iOB = rep.isOuterBorough();
- boolean isSHours = rep.duringHours(900,1520);
- if(isFemale && iOB && isSHours){
- sumOfAges = sumOfAges + rep.getAge();
- cOfReports++;
- }
- }
- return sumOfAges / cOfReports;
- }
- /**
- * Given an array of stop and frisk reports,
- * returns the youngest age of all the men who were stopped
- * in Manhattan in the hours BEFORE or AFTER AFSE's school
- * hours.
- *
- * @param reports An array of StopFriskReports
- * @return the youngest age of all men stopped in
- * Manhattan in hours before or after AFSE's school hours
- */
- public static int youngestAgeMManhattanNoSchool(StopFriskReport[] reports)
- {
- int youngest = Integer.MAX_VALUE;
- for(int i = 0; i < reports.length; i++)
- {
- StopFriskReport rep = reports[i];
- String gender = rep.getGender();
- boolean isMale = gender.equals("M");
- boolean isManHat = !(rep.isOuterBorough());
- boolean isBAHrs = !(rep.duringHours(900, 1520));
- if(rep.getAge() < youngest && isMale && isManHat && isBAHrs)
- {
- youngest = rep.getAge();
- }
- }
- return youngest;
- }
- /**
- * Given an array of stop and frisk reports,
- * determine whether there were more MORNING (12:00 AM -
- * 11:59 AM) stops of men in Manhattan or more AFTERNOON
- * (12:00 PM - 11:59 PM) stops of men in Manhattan. Return
- * "More A.M." if there were more morning stops, "More P.M"
- * if there were more afternoon stops, and "Neither"
- * otherwise.
- *
- * @param reports An array of StopFriskReports
- * @return "More A.M." when there are more morning stops of
- * men in Manhattan, "More P.M" when there are more afternoon
- * stops of men in Manhattan, "Neither" otherwise.
- */
- public static String moreAMOrPMManhattanM(StopFriskReport[] reports)
- {
- int mStops = 0;
- int nStops = 0;
- String PM = "More P.M.";
- String AM = "More A.M.";
- String none = "Neither";
- for(int i = 0; i < reports.length; i++){
- StopFriskReport rep = reports[i];
- String gender = rep.getGender();
- boolean isMale = gender.equals("M");
- boolean isManHat = !(rep.isOuterBorough());
- boolean mor = rep.duringHours(0000, 1159);
- boolean night = rep.duringHours(1200, 2400);
- if(isMale && isManHat && mor)
- {
- mStops++;
- }
- if(isMale && isManHat && night)
- {
- nStops++;
- }
- }
- if(mStops > nStops)
- {
- return AM;
- }
- else if(nStops > mStops)
- {
- return PM;
- }
- else
- {
- return none;
- }
- }
- /**
- * Given an array of stop and frisk data reports,
- * return the report of the oldest man stopped in outer
- * boroughs.
- *
- * @param reports An array of StopFriskReports
- * @return the StopFriskReport of the oldest man stopped in
- * the outer boroughs
- */
- public static StopFriskReport oldestMOuterReport(StopFriskReport[] reports)
- {
- int age = Integer.MIN_VALUE;
- StopFriskReport repo = reports[0];
- for(int i = 0; i < reports.length; i++)
- {
- StopFriskReport rep = reports[i];
- String gender = rep.getGender();
- boolean isMale = gender.equals("M");
- boolean iOB = rep.isOuterBorough();
- if(rep.getAge() > age && isMale && iOB)
- {
- age = rep.getAge();
- repo = rep;
- }
- }
- return repo;
- //i did this at like 2 in the morning -> memory trigger word is "doublemint gum" please do not judge my style of memory
- }
- /**
- * Given an array of stop and frisk data reports,
- * return the reports of stops that occurred in the afternoon
- * (i.e. 12:00 PM - 11:59 PM) in outer boroughs.
- *
- * @param reports An array of StopFriskReports
- * @return the StopFriskReports of stops that occurred in
- * the afternoon in outer boroughs
- */
- public static StopFriskReport[] getAfternoonOuterReports(StopFriskReport[] reports)
- {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement