Advertisement
G_Burlakova

StudentsArrayFifthTerm

Nov 30th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package gabriela_burlakova;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11.  *
  12.  * @author Gaby
  13.  */
  14. public class Gabriela_Burlakova {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         Scanner sc = new Scanner(System.in);
  21.        
  22.         int numStudents;
  23.        
  24.         do {
  25.             System.out.println("Въведи брой студенти!");
  26.             numStudents = sc.nextInt();
  27.             if (numStudents > 30){
  28.                 System.out.println("Въведеният брой студенти е по-голям от допустимия.");
  29.             }
  30.         }while (numStudents > 30);
  31.        
  32.         double gSum = 0;
  33. //       General Sum - Сумата се използва за изчисляване средния успеха на всички студенти
  34.         double gAvr = 0;
  35. //       General Average - Среден успех за всички студенти
  36.         int numMarks = numStudents * 5;
  37. //        Общ брой оценки
  38.         double sAvr = 0;
  39. //        Среден успех за отделния студент
  40.         double avrMax = 0;
  41. //        Съхранява най-високия среден успех
  42.         int maxIndex = 0;
  43. //        Номерът на студента с най-висок среден успех
  44.         double avrMin = 6;
  45. //        Съхранява най-ниския среден успех
  46.         int minIndex = 0;
  47. //        Номерът на студента с най-висок среден успех
  48.         int aboveC = 0;
  49. //        Брой студенти със среден успех, по-висок от средния
  50.         int belowC = 0;
  51. //        Брой студенти със среден успех, по-нисък от средния
  52.  
  53.         double arrayStudents[][] = new double[numStudents][5];
  54.  
  55.  
  56.  
  57.         for (int i = 0; i < numStudents; i++) {
  58.             for (int j = 0; j < 5; j++) {
  59.                 do{
  60.                     System.out.println("Въведи оценка №" + (j + 1) + " за студент №" + (i + 1));
  61.                     arrayStudents[i][j] = sc.nextDouble();
  62.                     if(arrayStudents[i][j] < 2 || arrayStudents[i][j] > 6){
  63.                         System.out.println("Въведените оценки трябва да са между 2 и 6");
  64.                     }
  65.  
  66.                 }while (arrayStudents[i][j] < 2 || arrayStudents[i][j] > 6);
  67.  
  68.                 gSum = gSum + arrayStudents[i][j];
  69.             }
  70.  
  71.         }
  72.  
  73.         gAvr = (double) gSum / numMarks;
  74.  
  75.         for (int i = 0; i < numStudents; i++) {
  76.             double sSum = 0;
  77.             sAvr = 0;
  78.             for (int j = 0; j < 5; j++) {
  79.                 sSum = sSum + arrayStudents[i][j];
  80.             }
  81.             sAvr = (double) sSum / 5;
  82.             if (sAvr > avrMax) {
  83.                 avrMax = sAvr;
  84.                 maxIndex = (i + 1);
  85.             }
  86.             if (sAvr < avrMin) {
  87.                 avrMin = sAvr;
  88.                 minIndex = (i + 1);
  89.             }
  90.             if (sAvr > gAvr) {
  91.                 aboveC++;
  92.             } else {
  93.                 belowC++;
  94.             }
  95.  
  96.         }
  97.         System.out.println("Средният успех на студентите през 5 семестър е " + gAvr);
  98.         System.out.println();
  99.         System.out.println("Номерът на студента с най-висок среден успех е " + maxIndex + "\nсъс среден успех " + avrMax);
  100.         System.out.println();
  101.         System.out.println("Номерът на студента с най-нисък среден успех е " + minIndex + "\nсъс среден успех " + avrMin);
  102.         System.out.println();
  103.         System.out.println("Броят на студентите, които имат среден успех,\nнад средния е " + aboveC);
  104.         System.out.println();
  105.         System.out.println("Броят на студентите, които имат среден успех,\nпод средния е " + belowC);
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement