- float[] maxTemperatures = {25.3,31.8,40.6,24.6,17.8,27.5,32.3,35.3,42.1,22.6,25.1,30.2,34.1,32.5
- ,26.5,23.6,24,26.1,22.2,20.1,27.4,25.9,20.9,23.7,25.7,26.6,27.1,30.8,38.8,43.3,35.6};
- // Set up canvas size
- size(400, 300);
- // Define temperature ranges
- String[] temperatureRanges = {"0-10", "11-20", "21-30", "31-40", "41-50"};
- // Count of days for each temperature range
- int[] temperatureCounts = new int[5];
- // Fill temperatures by range
- for (float temp : maxTemperatures) {
- if (temp >= 0 && temp <= 10) {
- temperatureCounts[0]++;
- } else if (temp >= 11 && temp <= 20) {
- temperatureCounts[1]++;
- } else if (temp >= 21 && temp <= 30) {
- temperatureCounts[2]++;
- } else if (temp >= 31 && temp <= 40) {
- temperatureCounts[3]++;
- } else if (temp >= 41 && temp <= 50) {
- temperatureCounts[4]++;
- }
- }
- // Set text and rectangle parameters
- textSize(15);
- fill(0);
- textAlign(CENTER, CENTER);
- int x = 50; // Starting x-coordinate for the table
- int y = 50; // Starting y-coordinate for the table
- int rowHeight = 30; // Height of each row
- int columnWidth = 150; // Width of each column
- // Draw table outline
- stroke(0);
- noFill();
- rect(x, y, columnWidth * 2, rowHeight * (temperatureRanges.length + 1));
- // Draw table headers
- fill(200);
- rect(x, y, columnWidth, rowHeight);
- rect(x + columnWidth, y, columnWidth, rowHeight);
- fill(0);
- text("Temperature Range (\u00B0C)", x + 75, y + 15);
- text("Number of Days", x + columnWidth + 75, y + 15);
- y += rowHeight; // Move to the next row
- // Draw table rows
- for (int i = 0; i < temperatureRanges.length; i++) {
- if (i % 2 == 0) {
- fill(240);
- } else {
- fill(255);
- }
- rect(x, y, columnWidth, rowHeight);
- rect(x + columnWidth, y, columnWidth, rowHeight);
- fill(0);
- text(temperatureRanges[i], x + 75, y + 15);
- text(temperatureCounts[i], x + columnWidth + 75, y + 15);
- y += rowHeight; // Move to the next row
- }
- save("Activity18.png");