elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  El código no va....
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: El código no va....  (Leído 2,117 veces)
aletecno

Desconectado Desconectado

Mensajes: 3


Ver Perfil
El código no va....
« en: 5 Abril 2014, 23:51 pm »

Hola chicos,

son ya 3 dias que no consigo solucionar este programa...he hecho un montón de pruebas, este es el ultimo borrador que hice...

El programa debería:

- Hacer un promedio de las notas de las materias de cada alumno
- Imprimir los aprobados (promedio > 4,5)
- Imprimir el numero de promedios > 8
- Imprimir el numero de promedios < 4
- Imprimir el promedios máximo

import java.util.Scanner;



public class PRUEBAS {

private static final int NUM_ALUMNOS = 2;
private static final int MATERIAS = 3;

public static void main(String[] args) {
Scanner teclat = new Scanner(System.in);
float nota;
float notaFinal=0;
int aprovats=0;
int inferior = 0;
int superior = 0;
float promedio = 0;
float notaMax = 0;

System.out.println(“Introducció qualificacions FOL (Formació i Orientació laboral).”);

for(int indAlumne=0; indAlumne<NUM_ALUMNOS; indAlumne++){

for (int i=0; i 0) {
notaMax = notaFinal;
}
} while ((nota 10.0));
}
promedio = notaFinal/MATERIAS;
System.out.println(“Promedio: ” + promedio);
if ((promedio > 8) && (promedio 4.5) && (promedio <= 10)) {
aprovats++;
} else if ((promedio = 0)){
inferior++;
} else {
nota=0;
}
}

System.out.println(“Alumnes que han aprobado : “+ aprovats + “.”);
System.out.println (“Numero alumnos con nota inferior a 4: ” + inferior + ” (” + inferior* 100 / NUM_ALUMNOS + “%).”);
System.out.println (“Número alumnos con nota superior a 8: ” + superior + ” (” + superior* 100 / NUM_ALUMNOS + “%).”);
System.out.println(“La nota maxima es: ” + notaMax);
}
}

Alguien puede corregirlo para que salga correcto?

Gracias.


En línea

Mitsu

Desconectado Desconectado

Mensajes: 259



Ver Perfil WWW
Re: El código no va....
« Respuesta #1 en: 6 Abril 2014, 15:59 pm »

Es un algoritmo muy sencillo, puedes hacerlo con matrices así:

Código
  1. import java.util.Scanner;
  2.  
  3. public class NotaSys {
  4.  Scanner read;
  5.  
  6.  public Object[][] fillStudents() {
  7.    read = new Scanner(System.in);
  8.    System.out.println("Cuantos alumnos desea procesar?");
  9.    int cant_stud = read.nextInt();
  10.    System.out.println("Cuantas notas se van a promediar?");
  11.    int cant_calif = read.nextInt();
  12.    Object[][] students = new Object[cant_stud][cant_calif+1];
  13.  
  14.    for(byte i=0; i<students.length; i++) {
  15.      for(byte k=0; k<students[i].length; i++) {
  16.        if(k==0) {
  17.          System.out.println("Ingrese el nombre del alumno:");
  18.          students[i][k] = read.nextLine();
  19.          read.next();
  20.        }
  21.        else {
  22.          System.out.println("Ingrese la nota del alumno:");
  23.          students[i][k] = read.nextInt();
  24.        }
  25.      }
  26.    }
  27.    return students;
  28.  }
  29.  
  30.    public Object[][] getAverage(Object[][] students) {
  31.  
  32.      Object[][] average = new Object[students.length][2];
  33.      for(byte i=0; i<students.length; i++) {
  34.        double total = 0d; // suma las notas
  35.        for(byte k=0; k<students[i].length; i++) {
  36.          if(k!=0) {
  37.            total += students[i][k];
  38.          }
  39.          if(k==students[i].length) {
  40.            average[i][0] = students[i][0]; // guarda el nombre
  41.            average[i][k] = total / students[i].length-1; // y el promedio
  42.          }
  43.        }
  44.      }
  45.      return average;
  46.    }
  47.  
  48.    public double getMaxAverage(Object average[][]) {
  49.      double max = 0d;
  50.      double prom = average[0][1];
  51.  
  52.      for(byte i=0; i<average.length; i++) {
  53.        for(byte k=0; k<average.length; i++) {
  54.          if(k!=0) {
  55.            if(average[i][k] > prom) {
  56.              max = prom;
  57.            }
  58.          }
  59.        }
  60.      }
  61.      return max;
  62.    }
  63.  
  64.    public byte getApproved(Object[][] average) {
  65.      byte cant = 0;
  66.      for(byte i=0; i<average.length; i++) {
  67.        for(byte k=0; k<average.length; i++) {
  68.          if(k!=0) {
  69.            if(k > 4.5) {
  70.              cant++;
  71.            }
  72.          }
  73.        }
  74.      }
  75.      return cant;
  76.    }
  77.  
  78.    public byte getApprovedPlus8(Object[][] average) {
  79.      byte cant = 0;
  80.      for(byte i=0; i<average.length; i++) {
  81.        for(byte k=0; k<average.length; i++) {
  82.          if(k!=0) {
  83.            if(k > 8) {
  84.              cant++;
  85.            }
  86.          }
  87.        }
  88.      }
  89.      return cant;
  90.    }
  91.  
  92.    public byte getDisapproved(Object[][] average) {
  93.      byte cant = 0;
  94.      for(byte i=0; i<average.length; i++) {
  95.        for(byte k=0; k<average.length; i++) {
  96.          if(k!=0) {
  97.            if(k < 4.5) {
  98.              cant++;
  99.            }
  100.          }
  101.        }
  102.      }
  103.      return cant;
  104.    }
  105.  
  106.    public static void main(String[] args) {
  107.      NotaSys n = new NotaSys();
  108.      Object[][] myStudents = n.fillStudents();
  109.      Object[][] average = n.getAverage();
  110.      double max = n.getMaxAverage(average);
  111.      double cant_approved = n.getApproved(average);
  112.      double approved8 = n.getApprovedPlus8(average);
  113.      double disapproved = n.getDisapproved(average);
  114.  
  115.      // imprimes
  116.    }
  117.  
  118.  
  119.  }

Lo he hecho en un editor de texto así que quizás tiene algunos errores pero la idea es esa. Salu2.


« Última modificación: 6 Abril 2014, 16:24 pm por Mitsu » En línea

aletecno

Desconectado Desconectado

Mensajes: 3


Ver Perfil
Re: El código no va....
« Respuesta #2 en: 6 Abril 2014, 18:41 pm »

Hola, agradezco mucho tu respuesta. Y tu proposición está muy bien...el problema es que me estoy volviendo loco porque hay que resolver el ejercicio sólo con estructuras while, for, if...con variabile a y costantes però sin vectores...con el Scanner y nada mas...por esto no me sale...
En línea

aletecno

Desconectado Desconectado

Mensajes: 3


Ver Perfil
Re: El código no va....
« Respuesta #3 en: 8 Abril 2014, 14:33 pm »

Hola gente...ya lo he resuelto...me ha costado 2 dias de faena pero bien!!!!!!! :)
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines