Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class FINAL {
  4.  
  5. //Crear la matriz de calificaciones de 20x10
  6. public static String[][] matrizNotas = new String[20][10];
  7. public static Scanner sc = new Scanner(System.in);
  8. public static int alumnoCalif = 0;
  9.  
  10. public static void main(String[] args) {
  11.  
  12. int opcion = 0;
  13. while(opcion != 7){
  14. System.out.println("**********************\n"
  15. + "1. Ingresar datos del alumno\n"
  16. + "2. Ingresar calificación\n"
  17. + "4. Reportes por actividad\n"
  18. + "6. Imprimir matriz de notas\n"
  19. + "7. Salir\n"
  20. + "**********************");
  21. opcion = sc.nextInt();
  22.  
  23. switch(opcion){
  24. case 1: ingresarAlumno();
  25. break;
  26. case 2: califs();
  27. break;
  28. case 4: reportesPorActividad();
  29. break;
  30. case 6: imprimirMatriz();
  31. break;
  32. }
  33.  
  34. }
  35.  
  36. }
  37.  
  38. public static void imprimirMatriz(){
  39. for (int i = 0; i < matrizNotas.length; i++) {
  40. System.out.println(Arrays.toString(matrizNotas[i]));
  41. }
  42. }
  43.  
  44. public static void ingresarAlumno(){
  45. System.out.println("Selecciona el número de alumno a ingresar (1-20) puedes escribir 0 si no sabes en cuál vas.");
  46. int alumno = sc.nextInt();
  47.  
  48. //Pedir el nombre:
  49. System.out.println("Ingresa el nombre del alumno:");
  50. String nombre = sc.next();
  51.  
  52. if(alumno != 0){
  53. matrizNotas[alumno-1][0] = nombre;
  54. }
  55. else{
  56. int indice = -1;
  57. for (int i = 0; i < matrizNotas.length; i++) {
  58. if(matrizNotas[i][0] == null){
  59. indice = i;
  60. break;
  61. }
  62. }
  63. if(indice != -1){
  64. matrizNotas[indice][0] = nombre;
  65. }
  66. else{
  67. System.out.println("Matriz llena");
  68. }
  69. }
  70. }
  71.  
  72. public static void califs(){
  73. System.out.println("Selecciona el número de alumno a ingresar (1-20) puedes escribir 0 si no sabes en cuál vas.");
  74. alumnoCalif = sc.nextInt();
  75.  
  76. int opciones = 0;
  77. while(opciones != 9){
  78. System.out.println("**********************\n"
  79. + "1. Ingresar nota tarea 1\n"
  80. + "2. Ingresar nota tarea 2\n"
  81. + "3. Ingresar nota tarea 3\n"
  82. + "4. Ingresar nota tarea 4\n"
  83. + "5. Ingresar nota examen parcial 1\n"
  84. + "6. Ingresar nota examen parcial 2\n"
  85. + "6. Ingresar nota proyecto final"
  86. + "7. Ingresar nota examen final\n"
  87. + "9. Salir"
  88. + "**********************");
  89. opciones = sc.nextInt();
  90.  
  91. switch(opciones){
  92. case 1: tarea1();
  93. break;
  94. case 2: tarea2();
  95. break;
  96. /*case 3: tarea3();
  97. break;
  98. case 4: tarea4();
  99. break;
  100. case 5: actividad1();
  101. break;
  102. case 6: actividad2();
  103. break;
  104. case 7: proyeFin();
  105. break;
  106. case 8: exFinal();
  107. break;
  108. case 9: salir();
  109. break;*/
  110. }
  111.  
  112. }
  113.  
  114. }
  115. public static void tarea1(){
  116. System.out.println("Selecciona el número de alumno a ingresar (1-20) puedes escribir 0 si no sabes en cuál vas.");
  117. int alumno = sc.nextInt();
  118.  
  119. //Pedir el nombre:
  120. System.out.println("Ingresa la tarea 1 del alumno:");
  121. String calif1 = sc.next();
  122.  
  123. if(alumno != 1){
  124. matrizNotas[alumno-1][1] = calif1;
  125. }
  126. else{
  127. int indice = -1;
  128. for (int i = 0; i < matrizNotas.length; i++) {
  129. if(matrizNotas[i][1] == null){
  130. indice = i;
  131. break;
  132. }
  133. }
  134. if(indice != -1){
  135. matrizNotas[indice][1] = calif1;
  136. }
  137. else{
  138. System.out.println("Matriz llena");
  139. }
  140. }
  141. }
  142.  
  143. public static void tarea2(){
  144. System.out.println("Selecciona el número de alumno a ingresar (1-20) puedes escribir 0 si no sabes en cuál vas.");
  145. int alumno = sc.nextInt();
  146.  
  147. //Pedir el nombre:
  148. /*System.out.println("Ingresa la tarea 1 del alumno:");
  149. String calif1 = sc.next();
  150.  
  151. if(alumno != 1){
  152. matrizNotas[alumno-1][1] = calif1;
  153. }
  154. else{
  155. int indice = -1;
  156. for (int i = 0; i < matrizNotas.length; i++) {
  157. if(matrizNotas[i][1] == null){
  158. indice = i;
  159. break;
  160. }
  161. }
  162. if(indice != -1){
  163. matrizNotas[indice][1] = calif1;
  164. }
  165. else{
  166. System.out.println("Matriz llena");
  167. }
  168. }*/
  169. System.out.println("Ingresa la tarea 2 del alumno:");
  170. String calif2 = sc.next();
  171.  
  172. if(alumno != 1){
  173. matrizNotas[alumno-1][2] = calif2;
  174. }
  175. else{
  176. int indice = -1;
  177. for (int i = 0; i < matrizNotas.length; i++) {
  178. if(matrizNotas[i][2] == null){
  179. indice = i;
  180. break;
  181. }
  182. }
  183. if(indice != -1){
  184. matrizNotas[indice][2] = calif2;
  185. }
  186. else{
  187. System.out.println("Matriz llena");
  188. }
  189. }
  190. }
  191.  
  192. public static void reportesPorActividad(){
  193. System.out.println("Ingresa el número de actividad 1-9");
  194. int ac = sc.nextInt();
  195. System.out.println("Selecciona una opción\n"+
  196. "1. Promedio\n"+
  197. "2. Varianza\n"+
  198. "3. DevEst\n");
  199. int act = sc.nextInt();
  200.  
  201. if(act == 1){
  202. double promedio = obtenerPromedio(ac);
  203. System.out.println("El promedio es: " + promedio);
  204. }
  205. else if(act == 2){
  206.  
  207. double tot = 0;
  208. int cuantos = 0;
  209. double prom = obtenerPromedio(ac);
  210.  
  211. for (int i = 0; i < matrizNotas.length; i++) {
  212. if(matrizNotas[i][ac]!=null){
  213. tot += Math.pow(Double.parseDouble(matrizNotas[i][ac])-prom,2);
  214. cuantos++;
  215. }
  216. }
  217.  
  218. double varianza = tot/cuantos;
  219.  
  220.  
  221. System.out.println("La varianza es: " + varianza);
  222.  
  223.  
  224. }
  225. else{
  226. double tot = 0;
  227. int cuantos = 0;
  228. double prom = obtenerPromedio(ac);
  229.  
  230. for (int i = 0; i < matrizNotas.length; i++) {
  231. if(matrizNotas[i][ac]!=null){
  232. tot += Math.pow(Double.parseDouble(matrizNotas[i][ac])-prom,2);
  233. cuantos++;
  234. }
  235. }
  236.  
  237. double varianza = tot/cuantos;
  238.  
  239. varianza = Math.sqrt(varianza);
  240.  
  241.  
  242. System.out.println("La DevEst es: " + varianza);
  243. }
  244.  
  245. }
  246.  
  247. public static double obtenerPromedio(int col){
  248. //Calcular e imprimir promedio de esa col...
  249. double tot = 0;
  250. int cuantos = 0;
  251. for (int i = 0; i < matrizNotas.length; i++) {
  252. if(matrizNotas[i][col]!=null){
  253. tot += Double.parseDouble(matrizNotas[i][col]);
  254. cuantos++;
  255. }
  256. }
  257. double prom = tot/cuantos;
  258.  
  259. return prom;
  260. }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement