Big idea: Working with a data set means visiting its values one at a time and doing something with each. Planning on paper first makes the code easy.
Learning objectives
Represent patterns and algorithms that involve data sets found in everyday life using written language or diagrams.
Plan with a table
Before writing code, write a few sample rows and walk through what should happen to each. This is how you discover edge cases, like an empty list or a tie.
Day
High (°F)
Above 80?
Running count
Mon
78
no
0
Tue
83
yes
1
Wed
85
yes
2
Thu
79
no
2
The same plan in code
Code
int[] highs = {78, 83, 85, 79};
int hot = 0;
for (int h : highs) {
if (h > 80) hot++;
}
System.out.println(hot);
Output
2
Key points
A data set is a collection of specific pieces of information.
Analysis means accessing values one at a time and processing them toward a goal.
Charts and tables help plan the algorithm.
Watch out
Sketching sample data by hand is the fastest way to find edge cases.
Quick check
What questions could a table of (date, steps walked) answer?Show answer
For example: the average steps per day, the best day, how many days met a goal, or whether steps increased over time.