// Run program void setup() { size(200, 150); background(200, 255, 220); ArrayList newList = RNG(40); displayResults(sortHeights(newList), heightSum(newList), heightMean(newList)); save("activity22.png"); } // Function 1: (Psuedo) Randomly generate a list of heights between 100 to 200 ArrayList RNG(int number){ ArrayList heightList = new ArrayList(); for(int i = 0; i < number; i++){ heightList.add((int)round(random(100, 200))); } return heightList; } // Function 2: Sort the list into 3 categories (static list.) int[] sortHeights(ArrayList heightList){ int[] heightCategory = new int[3]; for(int i = 0; i < heightList.size(); i++){ if(heightList.get(i) < 134){ heightCategory[0]++; } else if(heightList.get(i) < 167){ heightCategory[1]++; } else { heightCategory[2]++; } } return heightCategory; } // Function 3: Calculate the sum of all heights int heightSum(ArrayList newList){ int sum = 0; for(int i = 0; i < newList.size(); i++){ sum = sum + newList.get(i); } return sum; } // Function 4: Calculate the mean of all heights float heightMean(ArrayList newList){ float mean = 0; for(int i = 0; i < newList.size(); i++){ mean = mean + newList.get(i) / newList.size(); } return mean; } // Function 5: Display results on the canvas. void displayResults(int[] sortHeights, int sum, float mean){ fill(0); textSize(14); text("Height 100-133: " + sortHeights[0], 10, 20); text("Height 133-166: " + sortHeights[1], 10, 40); text("Height 166-200: " + sortHeights[2], 10, 60); line(10, 70, 175, 70); text("Sum of all heights: " + sum, 10, 90); text("Mean height: " + mean, 10, 110); }