Alright, so i have numbers that i need to calculate in this code. And i need to calculate all the array numbers above 5.5 and set them into a .length so i can calculate the amount of sufficient scores. I also need to do this in the opposite. My attempt at the second tab is shown below with a method called geefAantalVoldoendes.
I can’t wrap my head around this.
Also i would appreciate feedback on the code so i can improve and understand what you would do or what would be the better practice.
ALSO! Thank god for Open Draft on this forum. I made a bunch of code and the power just shorted - lost almost everything but the forum function actually saved my code, lol.
Main tab
String bestand = "cijfers_klein.txt";
//String bestandGroot = "cijfers_groot.txt";
void setup() {
size(600, 400);
float[] cijfers = laadCijfers(bestand);
int arrayLength = geefAantal(cijfers);
float arrayHoogste = geefHoogste(cijfers);
float arrayLaagste = geefLaagste(cijfers);
float arrayGemiddelde = geefGemiddelde(cijfers);
int voldoendes = geefAantalVoldoendes(cijfers);
}
Second tab
/*
geefAantal,
geefHoogste,
geefLaagste,
geefGemiddelde,
geefAantalVoldoendes,
geefAantalOnvoldoendes
loadStrings()
*/
float[] laadCijfers(String bestand) {
float[] cijfers = float(loadStrings(bestand));
return cijfers;
}
static final int geefAantal(float[] laadArray) {
int cijfer = laadArray.length;
println("Print aantal cijfers: "+cijfer);
return int(cijfer);
}
float geefHoogste(float[] laadArray) {
float cijfer = laadArray[0];
for (int i = 1; i < laadArray.length; i++) {
if (laadArray[i] > cijfer) {
cijfer = laadArray[i];
}
}
println("Print hoogste cijfer: "+cijfer);
return cijfer;
}
float geefLaagste(float[] laadArray) {
float cijfer = laadArray[0];
for (int i = 1; i < laadArray.length; i++) {
if (laadArray[i] < cijfer) {
cijfer = laadArray[i];
}
}
println("Print laagste cijfer: "+cijfer);
return cijfer;
}
float geefGemiddelde(float[] laadArray) {
float cijfer = laadArray[0];
for (int i = 1; i < laadArray.length; i++) {
cijfer += laadArray[i];
}
cijfer /= laadArray.length;
println("Print gemiddelde cijfer: "+nf(cijfer, 1, 1));
return cijfer;
}
/*Voldoende is alles boven 5.5; dus GETAL >= 5.5 == voldoende.
- print lengte - alleen alles boven 5.5
*/
static final int geefAantalVoldoendes(float[] laadArray) {
float cijfer = laadArray[0];
float voldoende = 5.5;
for (final int i = 1; i < laadArray.length; i++) {
cijfer = laadArray[i];
if (cijfer >= voldoende) {
}
}
return int(cijfer);
}