Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.53 KB | None | 0 0
  1.  
  2. /**
  3. * Alejandra Cobo
  4. * A01654701
  5. * Date: 21/11/2018
  6. */
  7. import java.util.Scanner;
  8.  
  9. public class ProyectoFinal {
  10.  
  11. public static String[][] alumnos = new String[20][10];
  12.  
  13. public static void main(String[] args) {
  14.  
  15. Scanner scan = new Scanner(System.in);
  16. String respuesta = "";
  17. llenarMatriz();
  18.  
  19. while (respuesta.equals("7") == false) {
  20. System.out.println("****************************");
  21. System.out.println("1. Names");
  22. System.out.println("2. Grades");
  23. System.out.println("3. Report of each student");
  24. System.out.println("4. Report of activities");
  25. System.out.println("5. Performance Group ");
  26. System.out.println("6. Print Matrix");
  27. System.out.println("7. Exit");
  28. System.out.println("****************************");
  29. respuesta = scan.next();
  30.  
  31. switch (respuesta) {
  32. case "1":
  33. System.out.println("Number of the student that you wanna assigned a name (1-20)");
  34. String numAlumno = scan.next();
  35. System.out.println("Name of the student");
  36. String nombreAlumno = scan.next();
  37. asignarNombreAlumno(numAlumno, nombreAlumno);
  38.  
  39. break;
  40. case "2":
  41. System.out.println("Select the student (1-20)");
  42. String numAlu = scan.next();
  43. int aux = 1;
  44. do {
  45. System.out.println("Choose an activity:");
  46. System.out.println("****************************");
  47. System.out.println("1. Tarea 1");
  48. System.out.println("2. Tarea 2");
  49. System.out.println("3. Tarea 3");
  50. System.out.println("4. Tarea 4");
  51. System.out.println("5. Parcial 1");
  52. System.out.println("6. Parcial 2");
  53. System.out.println("7. Proyecto");
  54. System.out.println("8. Examen Final");
  55. System.out.println("9. Exit");
  56. System.out.println("****************************");
  57. String r2 = scan.next();
  58. if (!r2.equals("9")) {
  59. System.out.println("Grade of the activity: ");
  60. String calif = scan.next();
  61. asignarActividadAlumno(numAlu, r2, calif);
  62. }
  63. if (r2.equals("9")) {
  64. aux = 0;
  65. }
  66. } while (aux == 1);
  67. break;
  68. case "3":
  69. System.out.println("Choose the student (1-20)");
  70. String nAlumno = scan.next();
  71. System.out.println("Press 1 for the final average, press another number for the individually grades ");
  72. int caso3 = scan.nextInt();
  73. if (caso3 != 1) {
  74. System.out.println("Selecciona la nota que quieres consultar");
  75. System.out.println("****************************");
  76. System.out.println("1) Tarea 1");
  77. System.out.println("2) Tarea 2");
  78. System.out.println("3) Tarea 3");
  79. System.out.println("4) Tarea 4");
  80. System.out.println("5) Parcial 1");
  81. System.out.println("6) Parcial 2");
  82. System.out.println("7) Proyecto");
  83. System.out.println("8) Examen Final");
  84. System.out.println("****************************");
  85. String r3 = scan.next();
  86. preguntarNota(nAlumno, r3);
  87. } else {
  88. promedioAlumno(nAlumno);
  89. }
  90. break;
  91. case "4":
  92. System.out.println("Choose an activity ");
  93. System.out.println("****************************");
  94. System.out.println("1) Tarea 1");
  95. System.out.println("2) Tarea 2");
  96. System.out.println("3) Tarea 3");
  97. System.out.println("4) Tarea 4");
  98. System.out.println("5) Parcial 1");
  99. System.out.println("6) Parcial 2");
  100. System.out.println("7) Proyecto");
  101. System.out.println("8) Examen Final");
  102. System.out.println("9) Promedio Final");
  103. System.out.println("****************************");
  104. String r4 = scan.next();
  105. System.out.println("****************************");
  106. System.out.println("Choose an option:");
  107. System.out.println("1) Promedio");
  108. System.out.println("2) Varianza de la actividad");
  109. System.out.println("3) Desviación estandar de la actividad");
  110. System.out.println("****************************");
  111. String r5 = scan.next();
  112. switch (r5) {
  113. case "1":
  114. promedioPorActividad(r4);
  115. break;
  116. case "2":
  117. varianzaPorActividad(r4);
  118. break;
  119. case "3":
  120. desviacionPorActividad(r4);
  121. break;
  122. }
  123.  
  124. break;
  125. case "5":
  126. System.out.println("****************************");
  127. System.out.println("Choose an option: ");
  128. System.out.println("1) Promedio del grupo");
  129. System.out.println("2) Varianza del grupo");
  130. System.out.println("3) Desviación estandar del grupo");
  131. System.out.println("4) Número de aprobados y reprobados");
  132. System.out.println("****************************");
  133. String r6 = scan.next();
  134. switch (r6) {
  135. case "1":
  136. promedioPorActividad("9");
  137. break;
  138. case "2":
  139. varianzaPorActividad("9");
  140. break;
  141. case "3":
  142. desviacionPorActividad("9");
  143. break;
  144. case "4":
  145. numeroAprobadosReprobados();
  146. }
  147. break;
  148. case "6":
  149. imprimirMatriz();
  150. break;
  151. case "7":
  152. break;
  153. }
  154. }
  155. System.out.println("Thank you... bye.");
  156. }
  157.  
  158. public static void llenarMatriz() {
  159. for (int i = 0; i < 20; i++) {
  160. for (int j = 0; j < 10; j++) {
  161. if (j == 0) {
  162. alumnos[i][j] = "aaa";
  163. } else {
  164. int random = (int) (Math.random() * 50) + 50;
  165. String randomString = Integer.toString(random);
  166.  
  167. alumnos[i][j] = "" + random;
  168. }
  169. }
  170. }
  171. }
  172.  
  173. public static void imprimirMatriz() {
  174. System.out.println();
  175. for (int i = 0; i < 20; i++) {
  176. for (int j = 0; j < 10; j++) {
  177. System.out.print(alumnos[i][j] + ", ");
  178. }
  179. System.out.println();
  180. }
  181. }
  182.  
  183. public static void asignarNombreAlumno(String numA, String nomA) {
  184. int numero = Integer.parseInt(numA);
  185. alumnos[numero - 1][0] = nomA;
  186. }
  187.  
  188. public static void asignarActividadAlumno(String numAlumno, String numActividad, String calif) {
  189. int numeroAlumno = Integer.parseInt(numAlumno);
  190. int numeroActividad = Integer.parseInt(numActividad);
  191. alumnos[numeroAlumno - 1][numeroActividad] = calif;
  192. }
  193.  
  194. public static void preguntarNota(String nAlumno, String nActividad) {
  195. int numAlumno = Integer.parseInt(nAlumno);
  196. int nuActividad = Integer.parseInt(nActividad);
  197. String nota = alumnos[numAlumno - 1][nuActividad];
  198. System.out.println("The grade is: " + nota);
  199. }
  200.  
  201. public static void promedioAlumno(String noAlumno) {
  202. int numAlumno = Integer.parseInt(noAlumno);
  203. double t1 = Integer.parseInt(alumnos[numAlumno - 1][1]);
  204. double t2 = Integer.parseInt(alumnos[numAlumno - 1][2]);
  205. double t3 = Integer.parseInt(alumnos[numAlumno - 1][3]);
  206. double t4 = Integer.parseInt(alumnos[numAlumno - 1][4]);
  207. double p1 = Integer.parseInt(alumnos[numAlumno - 1][5]);
  208. double p2 = Integer.parseInt(alumnos[numAlumno - 1][6]);
  209. double proyecto = Integer.parseInt(alumnos[numAlumno - 1][7]);
  210. double efin = Integer.parseInt(alumnos[numAlumno - 1][8]);
  211.  
  212. double promedio = Math.round((((t1 + t2 + t3 + t4) / 4) * .4) + (((p1 + p2) / 2) * .15) + (proyecto * .25) + (efin * .2));
  213. alumnos[numAlumno - 1][9] = promedio + "";
  214. System.out.println("Average of the student: " + promedio);
  215. }
  216.  
  217. public static String[] calificacionesPorActividad(String actividad) {
  218. int numActividad = Integer.parseInt(actividad);
  219. String[] califs = new String[20];
  220. for (int i = 0; i < 20; i++) {
  221. califs[i] = alumnos[i][numActividad];
  222. }
  223. return califs;
  224. }
  225.  
  226. public static void promedioPorActividad(String actividad) {
  227. String[] califs = calificacionesPorActividad(actividad);
  228. double prom = 0;
  229. for (int i = 0; i < 20; i++) {
  230. prom += Double.parseDouble(califs[i]);
  231. }
  232. prom = prom / 20;
  233. System.out.println("Average of the activity: " + prom);
  234. }
  235.  
  236. public static void varianzaPorActividad(String actividad) {
  237. String[] califs = calificacionesPorActividad(actividad);
  238. String[] desvCal = calificacionesPorActividad(actividad);
  239. int numActividad = Integer.parseInt(actividad);
  240. //Desv = Raiz (X1-Promedio)2 + (X2-Prom)2 + (X3-Prom)2 + (X4-Prom)2 + (X5-Prom)2 + (X6-Prom)2 + ....)/20
  241. //Sacar promedio para la desviación estandar
  242. double prom = 0;
  243. for (int i = 0; i < 20; i++) {
  244. prom += Double.parseDouble(califs[i]);
  245. }
  246. prom = prom / 20;
  247.  
  248. //Sacar números interiores
  249. for (int i = 0; i < 20; i++) {
  250. califs[i] = alumnos[i][numActividad];
  251. desvCal[i] = califs[i];
  252.  
  253. }
  254.  
  255. double x1 = Double.parseDouble(desvCal[0]);
  256. double x2 = Double.parseDouble(desvCal[1]);
  257. double x3 = Double.parseDouble(desvCal[2]);
  258. double x4 = Double.parseDouble(desvCal[3]);
  259. double x5 = Double.parseDouble(desvCal[4]);
  260. double x6 = Double.parseDouble(desvCal[5]);
  261. double x7 = Double.parseDouble(desvCal[6]);
  262. double x8 = Double.parseDouble(desvCal[7]);
  263. double x9 = Double.parseDouble(desvCal[8]);
  264. double x10 = Double.parseDouble(desvCal[9]);
  265. double x11 = Double.parseDouble(desvCal[10]);
  266. double x12 = Double.parseDouble(desvCal[11]);
  267. double x13 = Double.parseDouble(desvCal[12]);
  268. double x14 = Double.parseDouble(desvCal[13]);
  269. double x15 = Double.parseDouble(desvCal[14]);
  270. double x16 = Double.parseDouble(desvCal[15]);
  271. double x17 = Double.parseDouble(desvCal[16]);
  272. double x18 = Double.parseDouble(desvCal[17]);
  273. double x19 = Double.parseDouble(desvCal[18]);
  274. double x20 = Double.parseDouble(desvCal[19]);
  275.  
  276. //Restar y multiplicar
  277. x1 = ((x1 - prom) * (x1 - prom));
  278. x2 = ((x2 - prom) * (x2 - prom));
  279. x3 = ((x3 - prom) * (x3 - prom));
  280. x4 = ((x4 - prom) * (x4 - prom));
  281. x5 = ((x5 - prom) * (x5 - prom));
  282. x6 = ((x6 - prom) * (x6 - prom));
  283. x7 = ((x7 - prom) * (x7 - prom));
  284. x8 = ((x8 - prom) * (x8 - prom));
  285. x9 = ((x9 - prom) * (x9 - prom));
  286. x10 = ((x10 - prom) * (x10 - prom));
  287. x11 = ((x11 - prom) * (x11 - prom));
  288. x12 = ((x12 - prom) * (x12 - prom));
  289. x13 = ((x13 - prom) * (x13 - prom));
  290. x14 = ((x14 - prom) * (x14 - prom));
  291. x15 = ((x15 - prom) * (x15 - prom));
  292. x16 = ((x16 - prom) * (x16 - prom));
  293. x17 = ((x17 - prom) * (x17 - prom));
  294. x18 = ((x18 - prom) * (x18 - prom));
  295. x19 = ((x19 - prom) * (x19 - prom));
  296. x20 = ((x20 - prom) * (x20 - prom));
  297.  
  298. double varianza = Math.round((x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20) / 19);
  299.  
  300. System.out.println("Varianza the la actividad :" + varianza);
  301. }
  302.  
  303. public static void desviacionPorActividad(String actividad) {
  304. String[] califs = calificacionesPorActividad(actividad);
  305. String[] desvCal = calificacionesPorActividad(actividad);
  306. int numActividad = Integer.parseInt(actividad);
  307. //Desv = Raiz (X1-Promedio)2 + (X2-Prom)2 + (X3-Prom)2 + (X4-Prom)2 + (X5-Prom)2 + (X6-Prom)2 + ....)/20
  308. //Sacar promedio para la desviación estandar
  309. double prom = 0;
  310. for (int i = 0; i < 20; i++) {
  311. prom += Double.parseDouble(califs[i]);
  312. }
  313. prom = prom / 20;
  314.  
  315. //Sacar números interiores
  316. for (int i = 0; i < 20; i++) {
  317. califs[i] = alumnos[i][numActividad];
  318. desvCal[i] = califs[i];
  319.  
  320. }
  321.  
  322. double x1 = Double.parseDouble(desvCal[0]);
  323. double x2 = Double.parseDouble(desvCal[1]);
  324. double x3 = Double.parseDouble(desvCal[2]);
  325. double x4 = Double.parseDouble(desvCal[3]);
  326. double x5 = Double.parseDouble(desvCal[4]);
  327. double x6 = Double.parseDouble(desvCal[5]);
  328. double x7 = Double.parseDouble(desvCal[6]);
  329. double x8 = Double.parseDouble(desvCal[7]);
  330. double x9 = Double.parseDouble(desvCal[8]);
  331. double x10 = Double.parseDouble(desvCal[9]);
  332. double x11 = Double.parseDouble(desvCal[10]);
  333. double x12 = Double.parseDouble(desvCal[11]);
  334. double x13 = Double.parseDouble(desvCal[12]);
  335. double x14 = Double.parseDouble(desvCal[13]);
  336. double x15 = Double.parseDouble(desvCal[14]);
  337. double x16 = Double.parseDouble(desvCal[15]);
  338. double x17 = Double.parseDouble(desvCal[16]);
  339. double x18 = Double.parseDouble(desvCal[17]);
  340. double x19 = Double.parseDouble(desvCal[18]);
  341. double x20 = Double.parseDouble(desvCal[19]);
  342.  
  343. //Restar y multiplicar
  344. x1 = ((x1 - prom) * (x1 - prom));
  345. x2 = ((x2 - prom) * (x2 - prom));
  346. x3 = ((x3 - prom) * (x3 - prom));
  347. x4 = ((x4 - prom) * (x4 - prom));
  348. x5 = ((x5 - prom) * (x5 - prom));
  349. x6 = ((x6 - prom) * (x6 - prom));
  350. x7 = ((x7 - prom) * (x7 - prom));
  351. x8 = ((x8 - prom) * (x8 - prom));
  352. x9 = ((x9 - prom) * (x9 - prom));
  353. x10 = ((x10 - prom) * (x10 - prom));
  354. x11 = ((x11 - prom) * (x11 - prom));
  355. x12 = ((x12 - prom) * (x12 - prom));
  356. x13 = ((x13 - prom) * (x13 - prom));
  357. x14 = ((x14 - prom) * (x14 - prom));
  358. x15 = ((x15 - prom) * (x15 - prom));
  359. x16 = ((x16 - prom) * (x16 - prom));
  360. x17 = ((x17 - prom) * (x17 - prom));
  361. x18 = ((x18 - prom) * (x18 - prom));
  362. x19 = ((x19 - prom) * (x19 - prom));
  363. x20 = ((x20 - prom) * (x20 - prom));
  364.  
  365. double desviacion = Math.round(Math.sqrt((x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20)));
  366.  
  367. System.out.println("Desviación estandar :" + desviacion);
  368. }
  369.  
  370. public static void numeroAprobadosReprobados() {
  371. String[] califs = calificacionesPorActividad("9");
  372. int aprobados = 0;
  373. int reprobados = 0;
  374. for (int i = 0; i < 20; i++) {
  375. double c = Double.parseDouble(califs[i]);
  376. if (c < 70) {
  377. reprobados++;
  378. } else {
  379. aprobados++;
  380. }
  381. }
  382. System.out.println("El número de aprobados es: " + aprobados + ", y el número de reprobados es: " + reprobados);
  383. }
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement