Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. public class StopFriskReportAnalyzer
  2. {
  3. /**
  4. * Given an array of stop and frisk reports,
  5. * returns the average age of all the women who were stopped
  6. * in outer boroughs during AFSE's school hours (9:00 AM to
  7. * 3:20 PM)
  8. *
  9. * @param data An array of StopFriskReports
  10. * @return the average age of all women stopped in outer
  11. * boroughs during AFSE's school hours
  12. */
  13. public static double avgAgeFOuterSchool(StopFriskReport[] reports)
  14. {
  15. double sumOfAges = 0;
  16. int cOfReports = 0;
  17. for(int i = 0; i < reports.length; i++){
  18. StopFriskReport rep = reports[i];
  19. String gender = rep.getGender();
  20. boolean isFemale = gender.equals("F");
  21. boolean iOB = rep.isOuterBorough();
  22. boolean isSHours = rep.duringHours(900,1520);
  23. if(isFemale && iOB && isSHours){
  24. sumOfAges = sumOfAges + rep.getAge();
  25. cOfReports++;
  26. }
  27.  
  28. }
  29. return sumOfAges / cOfReports;
  30. }
  31.  
  32. /**
  33. * Given an array of stop and frisk reports,
  34. * returns the youngest age of all the men who were stopped
  35. * in Manhattan in the hours BEFORE or AFTER AFSE's school
  36. * hours.
  37. *
  38. * @param reports An array of StopFriskReports
  39. * @return the youngest age of all men stopped in
  40. * Manhattan in hours before or after AFSE's school hours
  41. */
  42. public static int youngestAgeMManhattanNoSchool(StopFriskReport[] reports)
  43. {
  44. int youngest = Integer.MAX_VALUE;
  45. for(int i = 0; i < reports.length; i++)
  46. {
  47. StopFriskReport rep = reports[i];
  48. String gender = rep.getGender();
  49. boolean isMale = gender.equals("M");
  50. boolean isManHat = !(rep.isOuterBorough());
  51. boolean isBAHrs = !(rep.duringHours(900, 1520));
  52. if(rep.getAge() < youngest && isMale && isManHat && isBAHrs)
  53. {
  54. youngest = rep.getAge();
  55. }
  56. }
  57. return youngest;
  58. }
  59.  
  60. /**
  61. * Given an array of stop and frisk reports,
  62. * determine whether there were more MORNING (12:00 AM -
  63. * 11:59 AM) stops of men in Manhattan or more AFTERNOON
  64. * (12:00 PM - 11:59 PM) stops of men in Manhattan. Return
  65. * "More A.M." if there were more morning stops, "More P.M"
  66. * if there were more afternoon stops, and "Neither"
  67. * otherwise.
  68. *
  69. * @param reports An array of StopFriskReports
  70. * @return "More A.M." when there are more morning stops of
  71. * men in Manhattan, "More P.M" when there are more afternoon
  72. * stops of men in Manhattan, "Neither" otherwise.
  73. */
  74. public static String moreAMOrPMManhattanM(StopFriskReport[] reports)
  75. {
  76. int mStops = 0;
  77. int nStops = 0;
  78. String PM = "More P.M.";
  79. String AM = "More A.M.";
  80. String none = "Neither";
  81. for(int i = 0; i < reports.length; i++){
  82. StopFriskReport rep = reports[i];
  83. String gender = rep.getGender();
  84. boolean isMale = gender.equals("M");
  85. boolean isManHat = !(rep.isOuterBorough());
  86. boolean mor = rep.duringHours(0000, 1159);
  87. boolean night = rep.duringHours(1200, 2400);
  88. if(isMale && isManHat && mor)
  89. {
  90. mStops++;
  91. }
  92. if(isMale && isManHat && night)
  93. {
  94. nStops++;
  95.  
  96. }
  97. }
  98. if(mStops > nStops)
  99. {
  100. return AM;
  101. }
  102. else if(nStops > mStops)
  103. {
  104. return PM;
  105. }
  106. else
  107. {
  108. return none;
  109. }
  110. }
  111.  
  112. /**
  113. * Given an array of stop and frisk data reports,
  114. * return the report of the oldest man stopped in outer
  115. * boroughs.
  116. *
  117. * @param reports An array of StopFriskReports
  118. * @return the StopFriskReport of the oldest man stopped in
  119. * the outer boroughs
  120. */
  121. public static StopFriskReport oldestMOuterReport(StopFriskReport[] reports)
  122. {
  123. int age = Integer.MIN_VALUE;
  124. StopFriskReport repo = reports[0];
  125. for(int i = 0; i < reports.length; i++)
  126. {
  127. StopFriskReport rep = reports[i];
  128. String gender = rep.getGender();
  129. boolean isMale = gender.equals("M");
  130. boolean iOB = rep.isOuterBorough();
  131.  
  132. if(rep.getAge() > age && isMale && iOB)
  133. {
  134. age = rep.getAge();
  135. repo = rep;
  136. }
  137.  
  138. }
  139. return repo;
  140. //i did this at like 2 in the morning -> memory trigger word is "doublemint gum" please do not judge my style of memory
  141. }
  142.  
  143.  
  144. /**
  145. * Given an array of stop and frisk data reports,
  146. * return the reports of stops that occurred in the afternoon
  147. * (i.e. 12:00 PM - 11:59 PM) in outer boroughs.
  148. *
  149. * @param reports An array of StopFriskReports
  150. * @return the StopFriskReports of stops that occurred in
  151. * the afternoon in outer boroughs
  152. */
  153. public static StopFriskReport[] getAfternoonOuterReports(StopFriskReport[] reports)
  154. {
  155. return null;
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement