help with java code

0

Enter the data of n students (cut with "end *"). The course can be A or B. Name, course, grade, sex, age. Calculate and print:

  • Number of approved students (approved with 6), per course.
  • Number of students postponed, per course.
  • Average age, general and by course.
  • Average grade of male students, per course. Show results on the screen using windows through the JOptionPane class.
  • I DO NOT KNOW HOW TO PRINT THE RESULTS BY WINDOW (jOPTIONPANE) AND CREATE THE COURT "END" WITH A QUESTION.

    package tp; import java.util.Scanner; public class data {public static void main (String [] args) {

    int i, edadA=0, edadB=0, cantA=0,cantB=0,edadG=0,notVA=0,notVB=0,cantVA=0,cantVB=0;
    double predadA, predadB,predadG,prnotVA,prnotVB;
    int notA=0, notB=0, cantaprA=0, cantaprB=0,cantaplA=0,cantaplB=0,canteG=0;
    
    int nota[]; 
    nota = new int[8];
    
    String nombre[];
    nombre = new String[8]; 
    
    String curso[];
    curso = new String[8]; 
    
    String sexo[];
    sexo = new String[8];
    
    int edad[]; 
    edad = new int[8];
    
    Scanner input = new Scanner(System.in);
    
    for(i=0;i<8;i=i+1)
                {
    System.out.printf("Ingrese nombre alumno %d: ",i+1 ); 
    nombre[i] = input.next();
    System.out.printf("Ingrese curso alumno ( A/B) %d: ",i+1 ); 
    curso[i] = input.next();
    System.out.printf("Ingrese nota alumno %d: ",i+1 ); 
    nota[i] = input.nextInt();
    System.out.printf("Ingrese sexo alumno (F/M) %d: ",i+1 ); 
    sexo[i] = input.next(); 
    System.out.printf("Ingrese edad alumno %d: ",i+1 ); 
    edad[i] = input.nextInt();
    
    // EDAD PROMEDIO GENERAL
    
    edadG=edadG+edad[i];
    canteG=canteG+1;
    
    // EDAD PROMEDIO POR CURSO
    
    if (curso[i].equals("a")|| curso[i].equals("A") ){ 
        edadA= edadA+edad[i];
        cantA=cantA+1;     }
    
      else { 
          edadB=edadB+edad[i];
          cantB=cantB+1;   }
    
    // APROBADOS POR CURSO
    
    if (nota[i]>=6){
          if ( curso[i].equals ("a")|| curso[i].equals ("A")){
          notA=notA+nota[i];
          cantaprA=cantaprA+1;    }
    
          else {
          notB=notB+nota[i];
          cantaprB=cantaprB+1;  }
    
    }
    
    // APLAZADOS POR CURSO
    
    if (nota[i]<6){ 
          if ( curso[i].equals ("a")|| curso[i].equals ("A")){ 
          notA=notA+nota[i];
          cantaplA=cantaplA+1;
    }
    else { 
          notB=notB+nota[i];
          cantaplB=cantaplB+1;
    }
    }
    
    // NOTA PROMEDIO VARONES POR CURSO
    
    if (sexo[i].equalsIgnoreCase("m")) {
    
        if (curso[i].equalsIgnoreCase("a"))
        {
             notVA=notVA+nota[i];
             cantVA=cantVA+1;
        }else { 
               notVB=notVB+nota[i]; 
               cantVB=cantVB+1;   
    }
    }                      
        }   // aca termina el for
    
                   // imprimir calculos
    
        predadG=edadG/canteG;   
        System.out.print( "El promedio general de edad es: " + predadG + "\n" );
    
        predadA=edadA/cantA;
        System.out.print( "El promedio de edad del curso A es: " + predadA + "\n" );
    
        predadB=edadB/cantB;
        System.out.print( "El promedio de edad del curso B es: " + predadB + "\n");
    
        System.out.print( "La cantidad de alumnos aprobados en el curso A es de: " + cantaprA+ "\n");
    
        System.out.print( "La cantidad de alumnos aprobados en el curso B es de: " + cantaprB+"\n");
    
        System.out.print( "La cantidad de alumnos aplazados en el curso A es de: " + cantaplA+"\n");
    
        System.out.print( "La cantidad de alumnos aplazados en el curso B es de: " + cantaplB+"\n");
    
        prnotVA=notVA/cantVA; 
        System.out.print( "El promedio de alumnos varones en el curso A es de: " + prnotVA+"\n");
    
    
        prnotVB=notVB/cantVB;
        System.out.print( "El promedio de alumnos varones en el curso B es de: " + prnotVB+"\n");
    

    } }

        
    asked by Adriana Fernandez 26.06.2018 в 21:36
    source

    1 answer

    0

    Since the number of students is "n" I would advise you to use ArrayList, to be able to make them dynamic. For the ArrayList, you could create a class of student type, with the parameters you need, and in the class where you do the calculations you create an ArrayList of type "Student".

    ArrayList<Estudiante> estudiantes = new ArrayList<Estudiante>();
    
    
    String nombre = "";
    
    while(!nombre.equals("fin")){
            System.out.printf( "Ingrese nombre alumno %d\t",i+1 );            
            nombre = input.next();
            System.out.printf( "Ingrese curso alumno %d\t",i+1 ); 
            String curso = input.next();
            System.out.printf( "Ingrese nota alumno %d\t",i+1 ); 
            int nota = input.nextInt();
            System.out.printf( "Ingrese sexo alumno %d\t",i+1 ); 
            String sexo = input.next(); 
            System.out.printf( "Ingrese edad alumno %d\t",i+1 ); 
            int edad = input.nextInt();
    
    estudiantes.add(new Estudiante(nombre, curso, nota, sexo, edad);
    }
    
        
    answered by 28.06.2018 в 00:40