// Run program
void setup() {
size(200, 150);
background(200, 255, 220);
ArrayList<Integer> 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<Integer> RNG(int number){
ArrayList<Integer> heightList = new ArrayList<Integer>();
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<Integer> 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<Integer> 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<Integer> 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);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}