They ask me for a program, this should read the ages of the students of two classes separately, then I have created two arrays, class A, class B, read one class and then the ages of the other class, but the program asks that when they are introduced the ages are compared and if class B has students of the same age or lower than class A, a message must be shown on the screen.
It occurs to me to put the data of the two arrays class A, class B into a two-dimensional array and use the bubble loop to compare the ages with a counter that helps me see if class B will have students < = A classe A, but I do not know if it is possible to put two unidimensional arrays in a two-dimensional array.
I leave the code as far as I've come.
public class ProgramaDeClasesEac {
int[] classesA = null;
int[] classesB = null;
int[][] classesAiB = null;
Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
ProgramaDeClasesEac programa = new ProgramaDeClasesEac();
programa.inici();
}
private void inici() {
intro();
entraMida();
entraPosicions();
imprimeixPosicions();
}
private void intro() {
System.out.println("Aquest programa et demana que entris la mida de dos clases A y B.\n"
+ "Despres et demanara que entris les edats dels alumnes. \n"
+ "Una vegada estiguien entrades comparara les dues clases y retornara si la classe"
+ "<B> es mes gran que la classe <A>.");
}
private void entraMida() {
System.out.println("Digam la mida que tenen les clases A i B:");
if (scan.hasNextInt()) {
int mida = scan.nextInt();
classesA = new int[mida];
classesB = new int[mida];
classesAiB = new int[mida][mida];
} else {
scan.next();
System.out.print("Aquest valor no és correcte. ");
}
}
private void entraPosicions() {
for (int i = 0; i < classesA.length; i++) {
System.out.println("introdueix la posicio: " + (i + 1) + " de la clase A:");
classesA[i] = scan.nextInt();
}
for (int i = 0; i < classesB.length; i++) {
System.out.println("introdueix la posicio: " + (i + 1) + " de la clase B:");
classesB[i] = scan.nextInt();
}
}
private void imprimeixPosicions() {
System.out.print("Collectio 1: \n ");
for (int i = 0; i < classesA.length; i++) {
System.out.print(classesA[i] + " ");
}
System.out.println(" ");
System.out.print("Collectio 2: \n ");
for (int i = 0; i < classesB.length; i++) {
System.out.print(classesB[i] + " ");
}
System.out.println(" ");
}
private void Compara() {
for (int i = 0; i < classesAiB.length; i++) {
for (int j = 0; j < classesAiB.length; j++) {
}
}
}
}