Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.02 KB | None | 0 0
  1. package trabf;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TrabF {
  6.  
  7.     public static int[] lerPresencas() {
  8.         Scanner sc = new Scanner(System.in);
  9.         int v[] = new int[4];
  10.         System.out.println("Informar presença nos trimestres: ");
  11.             try {
  12.            for (int i = 0; i < 4; i++) {
  13.                 System.out.println((i + 1) + "° Trimestre: ");
  14.                 v[i] = sc.nextInt();
  15.                 while (v[i] < 0 || v[i] > 50) {
  16.                     System.out.println("Informar presença valida.");
  17.                     v[i] = sc.nextInt();
  18.                 }
  19.            }
  20.        }catch (java.util.InputMismatchException e) {
  21.             System.out.println("Informar um valor valido " + e);
  22.        }
  23.             return v;
  24.     }
  25.    
  26.     public static int[] notasTrm() {
  27.         int v[] = new int[4];
  28.         Scanner sc = new Scanner(System.in);
  29.         System.out.println("Informar nota dos trimestres: ");
  30.         for (int i = 0; i < 4; i++) {
  31.            
  32.                 do {
  33.                     System.out.println((i + 1) + "° Trimestre: ");
  34.                     v[i] = sc.nextInt();
  35.                     if (v[i] < 0) {
  36.                         System.out.println("Pontuação invalida, informar pontuação valida");
  37.                     }
  38.                 } while (v[i] < 0);
  39.                 if (i == 1 || i == 3) {
  40.                     while (v[i] > 30) {
  41.                         System.out.println("Pontuação maxima excedida,informe pontuação valida.");
  42.                         v[i] = sc.nextInt();
  43.                     }
  44.                 } else {
  45.                     while (v[i] > 20) {
  46.                         System.out.println("Pontuação maxima excedida,informe pontuação valida.");
  47.                         v[i] = sc.nextInt();
  48.                     }
  49.                 }
  50.            
  51.             }
  52.        
  53.         return v;
  54.     }
  55.     public static int semestre1(int notasTrim[][], int qAlunos, int notasFinaisSem[][]) {
  56.         Scanner sc = new Scanner(System.in);
  57.         int notaRec = 0;
  58.         int somaNotasSemestre1 = notasTrim[qAlunos][0] + notasTrim[qAlunos][1];
  59.         System.out.println("Soma das notas do primeiro semestre: " + somaNotasSemestre1 + " pontos");
  60.         if (somaNotasSemestre1 >= 30) {
  61.             notasFinaisSem[qAlunos][0] = somaNotasSemestre1;
  62.             System.out.println("Pontuação no semestre: " + notasFinaisSem[qAlunos][0]);
  63.             return 0;
  64.         } else {
  65.             System.out.println("Recuperação 1o semestre.");
  66.             System.out.println("Informar nota do exame de recuperação: ");
  67.             notaRec = sc.nextInt();
  68.             while (notaRec < 0 || notaRec > 50) {
  69.                 System.out.println("Pontuação invalida,informar pontuação valida");
  70.                 notaRec = sc.nextInt();
  71.             }
  72.             if (notaRec >= 30) {
  73.                 notasFinaisSem[qAlunos][0] = 30;
  74.                 System.out.println("Pontuação no primeiro semestre: " + notasFinaisSem[qAlunos][0]);
  75.  
  76.             } else if (notaRec > somaNotasSemestre1) {
  77.                 notasFinaisSem[qAlunos][0] = notaRec;
  78.                 System.out.println("Pontuação no semestre: " + notasFinaisSem[qAlunos][0]);
  79.             } else if (notaRec < somaNotasSemestre1) {
  80.                 notasFinaisSem[qAlunos][0] = somaNotasSemestre1;
  81.                 System.out.println("Pontuação no primeiro semestre: " + notasFinaisSem[qAlunos][0]);
  82.             }
  83.             while (notaRec < 0 || notaRec > 50) {
  84.                 System.out.println("Pontuação invalida,informar pontuação valida");
  85.                 notaRec = sc.nextInt();
  86.             }
  87.             return 1;
  88.         }
  89.     }
  90.     public static int semestre2(int notasTrim[][], int qAlunos, int notasFinaisSem[][]) {
  91.         Scanner sc = new Scanner(System.in);
  92.         int notaRec = 0;
  93.         int somaNotasSemestre2 = notasTrim[qAlunos][2] + notasTrim[qAlunos][3];
  94.         System.out.println("Soma das notas do segundo semestre: " + somaNotasSemestre2 + " pontos");
  95.         if (somaNotasSemestre2 >= 30) {
  96.             notasFinaisSem[qAlunos][1] = somaNotasSemestre2;
  97.             return 0;
  98.         } else {
  99.             System.out.println("Recuperação 2o semestre.");
  100.             System.out.println("Informar nota do exame de recuperação do segundo semestre: ");
  101.             notaRec = sc.nextInt();
  102.             while (notaRec < 0 || notaRec > 50) {
  103.                 System.out.println("Pontuação inválida,informar pontuação válida");
  104.                 notaRec = sc.nextInt();
  105.             }
  106.             if (notaRec >= 30) {
  107.                 notasFinaisSem[qAlunos][1] = 30;
  108.                 System.out.println("Pontuação no segundo semestre: " + notasFinaisSem[qAlunos][1]);
  109.             } else if (notaRec > somaNotasSemestre2) {
  110.                 notasFinaisSem[qAlunos][1] = notaRec;
  111.                 System.out.println("Pontuação no segundo semestre: " + notasFinaisSem[qAlunos][1]);
  112.             } else if (notaRec < somaNotasSemestre2) {
  113.                 notasFinaisSem[qAlunos][1] = somaNotasSemestre2;
  114.                 System.out.println("Pontuação no segundo semestre: " + notasFinaisSem[qAlunos][1]);
  115.             }
  116.             return 1;
  117.         }
  118.     }
  119.     public static int recFinal(int notasFinaisSem[][], int notasTrim[][], int qAlunos, int somaNotaFinal) {
  120.         Scanner sc = new Scanner(System.in);
  121.         int notaRec = 0;
  122.         int somaNotasSem1 = 0;
  123.         int somaNotasSem2 = 0;
  124.         somaNotaFinal = notasFinaisSem[qAlunos][0] + notasFinaisSem[qAlunos][1];
  125.         if (somaNotaFinal >= 40 && somaNotaFinal < 60) {
  126.             System.out.println("Recuperação FINAL.");
  127.             System.out.println("Informar nota da recuperação: ");
  128.             notaRec = sc.nextInt();
  129.             while (notaRec < 0 || notaRec > 100) {
  130.                 System.out.println("Informar pontuação valida: ");
  131.                 notaRec = sc.nextInt();
  132.             }
  133.             if (notaRec >= 60) {
  134.                 somaNotaFinal = 60;
  135.             } else if (notaRec > somaNotaFinal) {
  136.                 somaNotaFinal = notaRec;
  137.             }
  138.             return somaNotaFinal;
  139.         } else {
  140.             return -1;
  141.         }
  142.     }
  143.  
  144.     public static int aprovSe(int presenca, int notaFinal) {
  145.  
  146.         if (notaFinal >= 60 && presenca >= 75) {
  147.             System.out.println("Aprovado: " + notaFinal + " pontos" + ", " + " presença: " + presenca + "%");
  148.             return 1;
  149.         } else if (notaFinal >= 75 && presenca >= 50) {
  150.             System.out.println("Aprovado: " + notaFinal + " pontos," + "presença:  " + presenca + "%");
  151.             return 1;
  152.         } else {
  153.             System.out.println("Reprovado: " + notaFinal + " pontos" + ", " + " presença: " + presenca + "%");
  154.             return 0;
  155.         }
  156.     }
  157.     public static void imprimir(int notasTrim[][]) {
  158.         System.out.println("Relatório Final: ");
  159.         System.out.println("T1\tT2\tT3\tT4\t");
  160.         for (int a = 0; a < notasTrim.length; a++) {
  161.             for (int t = 0; t < notasTrim[0].length; t++) {
  162.                 System.out.print(notasTrim[a][t] + "\t");
  163.             }
  164.             System.out.println();
  165.         }
  166.     }
  167.     public static void main(String[] args) {
  168.         Scanner sc = new Scanner(System.in);
  169.         int somaNotasSemestre1 = 0, alunosRecSem = 0, alunosRecFinal = 0, notaFinal = 0;
  170.         int somaNotasSem1 = 0, somaNotaFinal = 0;
  171.  
  172.         int n = 0;
  173.         try {
  174.             System.out.println("Informar quantidade de alunos: ");
  175.             n = sc.nextInt();
  176.             while (n < 0) {
  177.                 System.out.println("Informar quantidade de alunos: ");
  178.                 n = sc.nextInt();
  179.             }
  180.             int notasTrim[][] = new int[n][4];
  181.             int presenca[][] = new int[n][4];
  182.             int notasFinaisSem[][] = new int[n][2];
  183.             int somaNotasSemestre2 = 0;
  184.             String situacao[] = new String[n];
  185.             int somaNotasSem2 = 0;
  186.             int apv = 0;
  187.             int rpv = 0;
  188.  
  189.             for (int qAlunos = 0; qAlunos < n; qAlunos++) {
  190.                 System.out.println("Informar nome: ");
  191.                 String nome = sc.next();
  192.                 notasTrim[qAlunos] = notasTrm();
  193.                 presenca[qAlunos] = lerPresencas();
  194.                 int recuperacao = semestre1(notasTrim, qAlunos, notasFinaisSem); // Verifica Recuperacao Sem 1
  195.                 if (recuperacao == 1) {
  196.                 }
  197.  
  198.                 recuperacao = semestre2(notasTrim, qAlunos, notasFinaisSem);  // Verifica Recuperacao Sem 2
  199.                 if (recuperacao == 1) {
  200.                 }
  201.  
  202.                 int rFinal = recFinal(notasFinaisSem, notasTrim, qAlunos, somaNotaFinal);
  203.                 if (rFinal != -1) {
  204.                     alunosRecFinal++;
  205.                     notaFinal = rFinal;
  206.                 } else {
  207.                     notaFinal = notasFinaisSem[qAlunos][0] + notasFinaisSem[qAlunos][1];
  208.                 }
  209.                 double somaPres = presenca[qAlunos][0] + presenca[qAlunos][1] + presenca[qAlunos][2] + presenca[qAlunos][3];
  210.                 somaPres = (Math.round((somaPres * 100) / 200));
  211.                 int s = (int) somaPres;
  212.                            
  213.                 int ap = aprovSe(s, notaFinal);
  214.                 if (ap == 1) {
  215.                     situacao[qAlunos] = nome + "APROVADO";
  216.                     apv++;
  217.                 } else {
  218.                     situacao[qAlunos] = nome + "REPROVADO";
  219.                     rpv++;
  220.                 }
  221.             }
  222.             imprimir(notasTrim);
  223.             System.out.println("Alunos aprovados: " + apv + " aluno(s)");
  224.             System.out.println("Alunos de recuperação final: " + alunosRecFinal + " aluno(s)");
  225.             System.out.println("Alunos reprovados: " + rpv + " aluno(s)");
  226.         } catch (java.util.InputMismatchException e) {
  227.             System.out.println("Informar um valor valido." + e);
  228.         }
  229.     }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement