私はプログラミングに不慣れですが、要素がユーザーによって選択されている場合は、要素ごとにグループ化する必要があります。したがって、groupbyに含まれる要素の数が正確にはわかりません。したがって、選択した要素の量をカウントするためにこれを行い、次に、必要な要素の量を表す正しいGroupbyステートメントを作成する別のステートメントを作成しました。
それは動作しますが、かさばるように見えます。これを行うためのより良い方法があるかどうかを確認したいと思いますか?
int totalOutPuts = 0;
totalOutPuts = endbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = coursebox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = departmentbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = callbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = daybox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = startbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = instructorbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = roombox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = buildingbox == true ? totalOutPuts + 1 : totalOutPuts;
totalOutPuts = numberenrolled == true ? totalOutPuts + 1 : totalOutPuts;
int missingElements = 10 - totalOutPuts;
String groupBy = " Group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10";
if (missingElements == 9) {
groupBy = " Group by 1";
} else if (missingElements == 8) {
groupBy = " Group by 1, 2";
} else if (missingElements == 7) {
groupBy = " Group by 1, 2, 3";
} else if (missingElements == 6) {
groupBy = " Group by 1, 2, 3, 4";
} else if (missingElements == 5) {
groupBy = " Group by 1, 2, 3, 4, 5";
} else if (missingElements == 4) {
groupBy = " Group by 1, 2, 3, 4, 5, 6";
} else if (missingElements == 3) {
groupBy = " Group by 1, 2, 3, 4, 5, 6, 7";
} else if (missingElements == 2) {
groupBy = " Group by 1, 2, 3, 4, 5, 6, 7, 8";
} else if (missingElements == 1) {
groupBy = " Group by 1, 2, 3, 4, 5, 6, 7, 8, 9";
}