Question: import java.util.ArrayList; /** * Data on drive times from home to work * * @author Jinpeng MO * @version 2018.6.6 */ public class DriveTimeData {

import java.util.ArrayList;

/** * Data on drive times from home to work * * @author Jinpeng MO * @version 2018.6.6 */ public class DriveTimeData { private ArrayList driveTimes; // drive time data in minutes

/** * Create and populate DriveTimeData */ public DriveTimeData() { driveTimes = new ArrayList<>(); populateData(); } /** * @return array list of drive time data */ public ArrayList getDriveTimes() { return driveTimes; }

/** * Add drive time data to the driveTimes array list * Each entry is the number of minutes it took to drive from * home to work on a particular day. */ private void populateData() { driveTimes.add(52); driveTimes.add(38); driveTimes.add(55); driveTimes.add(53); driveTimes.add(59); driveTimes.add(45); driveTimes.add(64); driveTimes.add(44); driveTimes.add(38); driveTimes.add(42); driveTimes.add(58); driveTimes.add(44); driveTimes.add(68); driveTimes.add(55); driveTimes.add(41); driveTimes.add(40); driveTimes.add(44); } }

import java.util.ArrayList;

/** * Analyze and display drive time data * * @author Jinpeng MO * @version 2018.6.1 */ public class DriveTimeDisplay { private ArrayList driveTimeData; private int[] counts;

/** * Create an object to analyze and display drive time data */ public DriveTimeDisplay() { driveTimeData = new DriveTimeData().getDriveTimes(); analyzeData(); } /** * Analyze the drive time data by filling in the array with frequency counts * for various drive time categories */ private void analyzeData() { // Record counts for the following categories: // < 40 minutes counts[0] // 40-49 minutes counts[1] // 50-59 minutes counts[2] // >= 60 minutes counts[3] counts = new int[4]; for (Integer minutes : driveTimeData) { if (minutes < 40) { counts[0]++; } else if (minutes >= 40 && minutes < 50) { counts[1]++; } else if (minutes >= 50 && minutes < 60) { counts[2]++; } else { counts[3]++; } } }

/** * Display drive time data */ public void displayData() { System.out.println("--------------------- Drive Time Data -----------------------"); System.out.println("Counts show # of days the drive time fell into each category"); System.out.println("< 40 minutes: " + counts[0]); System.out.println("40-49 minutes: " + counts[1]); System.out.println("50-59 minutes: " + counts[2]); System.out.println(">= 60 minutes: " + counts[3]); System.out.println("-------------------------------------------------------------"); } }

Your project should follow the same structure as the sample projects:

At least 2 classes, one for data and one for display.

An ArrayList collection for the raw data.

An array for the histogram.

A loop that processes the raw data and fills in the array with counts for the histogram.

In addition, your project should display the histogram using symbols for the frequency counts. (This is not shown in the sample projects.) For example, if the frequency count is 5 for a given category, display 5 asterisks: *****. If applied to the favorite color sample project, the histogram output might look like this:

 Blue: 1 * Green: 2 ** Red: 4 **** Yellow: 0 Other: 2 **

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!