TOPIC 4.2 · STUDY
Introduction to Using Data Sets
A data set is a collection of related pieces of information. Processing it means a written plan that looks at each value one at a time and builds a result such as a total, a maximum, or a count.
4.2.A
Introduction to using data sets
A data set is a collection of pieces of information kept together for a purpose. Harbor Snack Bar might list morning pastry sales by hour: 5 at 8 a.m., 8 at 9 a.m., and 6 at 10 a.m. Those three counts form one data set. A single number such as "8" is one value, not a data set.
Before any Java code, you describe how to process the collection in words or with a diagram. Charts and tables help you see each piece in order so you can plan looking at the next value, then the next, until none remain. Arrays belong in a later topic; here numbered steps are enough.
| Hour | Pastries sold |
|---|---|
| 8 a.m. | 5 |
| 9 a.m. | 8 |
| 10 a.m. | 6 |
A common plan totals every value. Students are expected to name steps like these: set total to 0; look at the next value; add that value to total; repeat looking and adding until every value has been used; report total. For 5, then 8, then 6, the running total is 5, then 13, then 19.
Each count is one piece of the data set. Adding them one at a time builds a single total.
The same one-at-a-time pattern works for other results. To find the busiest hour, start with the first count and replace the stored best when a later count is greater. To count how many hours sold more than 5 pastries, start a count at 0 and add 1 when a value meets the rule. Skipping leftover rows leaves the algorithm incomplete.
Key points
- A data set is a collection of pieces of information, not a single value.
- Processing means a written plan: access each item one at a time and update a result.
- A totaling plan sets total to 0, adds the next value, repeats until all are used, then reports total.
- Tables and diagrams help plan the next-value step without Java arrays.
- Other patterns include finding a maximum and counting values that meet a condition.
One number is not a data set. You need a collection of related pieces before you can traverse and accumulate a result.