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
/** * Create and populate DriveTimeData */ public DriveTimeData() { driveTimes = new ArrayList<>(); populateData(); } /** * @return array list of drive time data */ public ArrayList
/** * 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
/** * 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
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