Advertisement
daniel199410

Promedios clase

May 6th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.41 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package promedio;
  6. /**
  7.  *
  8.  * @author BLACKANGEL
  9.  */
  10. public class Promedio {
  11.    
  12.     private String[] tareasLloyd={"90","97","75","92"}, pruebasLloyd={"88","40","94"},examenesLloyd={"75","90"};
  13.     private String[] tareasAlice={"100","92","98","100"}, pruebasAlice={"82","83","91"},examenesAlice={"89","97"};
  14.     private String[] tareasTyler={"0","87","7522"}, pruebasTyler={"0","75","78"}, examenesTyler={"100","100"};
  15.     private String[][] Lloyd={{"Lloyd"}, tareasLloyd,pruebasLloyd,examenesLloyd};
  16.     private String[][] Alice={{"Alice"},tareasAlice,pruebasAlice,examenesAlice};
  17.     private String[][] Tylor={{"Tylor"}, tareasTyler,pruebasTyler,examenesTyler};
  18.     private String[][][] estudiantes={Lloyd, Alice, Tylor};
  19.    
  20.     private void print(){
  21.         for(int i=0; i<estudiantes.length; i++){
  22.             System.out.println(estudiantes[i][0][0]+":");
  23.             for(int j=1; j<estudiantes[i].length; j++){
  24.                 System.out.print("[");
  25.                 for(int k=0; k<estudiantes[i][j].length; k++){
  26.                     if(k==estudiantes[i][j].length-1)
  27.                         System.out.print(estudiantes[i][j][k]);
  28.                     else
  29.                         System.out.print(estudiantes[i][j][k]+", ");
  30.                 }
  31.                 System.out.print("]");
  32.                 System.out.println();
  33.             }
  34.         }
  35.     }
  36.    
  37.     private static String promedio(String[] lista){
  38.         double suma=0;
  39.         int cont=0;
  40.         double promedio=0;
  41.         for(int i=0; i<lista.length; i++){
  42.             suma+=Double.parseDouble(lista[i]);
  43.             cont++;
  44.         }
  45.         promedio=suma/cont;
  46.         return String.valueOf(promedio);
  47.     }
  48.    
  49.     private String calcularPromedio(String[][] lista){
  50.         double prom=0;
  51.         for(int i=1; i<lista.length; i++){
  52.             switch(i){
  53.                 case(1):
  54.                     prom=Double.parseDouble(promedio(lista[i]))*0.1;
  55.                     continue;
  56.                 case(2):
  57.                     prom+=Double.parseDouble(promedio(lista[i]))*0.3;
  58.                     continue;
  59.                 case(3):
  60.                     prom+=Double.parseDouble(promedio(lista[i]))*0.6;
  61.                     break;
  62.             }
  63.         }
  64.         return String.valueOf(prom);
  65.     }
  66.      
  67.     private String obtenerCalificaionenLetras(double nota){
  68.         nota=Math.round(nota);
  69.         if(nota>=90)
  70.         return "A";
  71.         if(nota>=80 & nota<90)
  72.             return "B";
  73.         if(nota>=70 & nota <80)
  74.             return "C";
  75.         if(nota>=60 & nota <70)
  76.             return "D";
  77.         if(nota<60)
  78.             return "F";
  79.         return " ";
  80.     }
  81.    
  82.     private String calcularPromedioClase(String [][][] lista) {
  83.         double promedio=0;
  84.         int cont=0;
  85.         double prom=0;
  86.         for(int i=0; i<lista.length; i++){
  87.             promedio+=Double.parseDouble(calcularPromedio(lista[i]));
  88.             cont++;
  89.         }
  90.         prom=promedio/cont;
  91.         return String.valueOf(prom);
  92.     }
  93.    
  94.     public static void main(String[] args) {
  95.         Promedio p1=new Promedio();        
  96.         System.out.println(p1.calcularPromedioClase(p1.estudiantes));
  97.         System.out.println(p1.obtenerCalificaionenLetras(Double.parseDouble(p1.calcularPromedioClase(p1.estudiantes))));
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement