Advertisement
amarek

Studenti

Jul 3rd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09._02._2019
  8. {
  9.     class Program
  10.     {
  11.         class Student
  12.         {
  13.             public double ExamPercent { get; private set; } // 0.0−1.0
  14.             public double AttendancePercent { get; private set; } // 0.0−1.0
  15.             public Student(double examPercent, double attendancePercent)
  16.             {
  17.                 if (examPercent > 1.0 || attendancePercent > 1.0) throw new ArgumentOutOfRangeException();
  18.                 if (examPercent < 0.0 || attendancePercent < 0.0) throw new ArgumentOutOfRangeException();
  19.                 ExamPercent = examPercent; AttendancePercent = attendancePercent;
  20.             }
  21.         }
  22.  
  23.         interface IGrader
  24.         {
  25.             List<bool> CreateNewStudentList(List<Student> student);
  26.             double CalculateAverage(List<Student> student);
  27.         }
  28.  
  29.         class FeritGrader : IGrader
  30.         {
  31.             public double MinScore { get; private set; }
  32.             public double MinAttendance { get; private set; }
  33.             public FeritGrader(double minScore, double minAttendance)
  34.             {
  35.                 //Kontrola granicnih vrijednosti je obavljena, ali izostavljena radi prostora
  36.                 MinScore = minScore; MinAttendance = minAttendance;
  37.             }
  38.  
  39.             public List<bool> CreateNewStudentList(List<Student> student) {
  40.                 List<bool> newStudentList = new List<bool>();
  41.                 for (int i = 0; i < student.Count(); i++)
  42.                 {
  43.                     if(student[i].ExamPercent > MinScore && student[i].AttendancePercent > MinAttendance)
  44.                     {
  45.                         newStudentList.Add(true);
  46.                     }
  47.                     else
  48.                     {
  49.                         newStudentList.Add(false);
  50.                     }
  51.                 }
  52.                 return newStudentList;
  53.             }
  54.  
  55.             public double CalculateAverage(List<Student> student) {
  56.                 double sum = 0;
  57.                 int counter = 0;
  58.                 for (int i = 0; i < student.Count(); i++)
  59.                 {
  60.                     if (student[i].ExamPercent > MinScore && student[i].AttendancePercent > MinAttendance)
  61.                     {
  62.                         sum = student[i].ExamPercent;
  63.                         counter++;
  64.                     }
  65.                 }
  66.                 return sum / counter;
  67.             }
  68.         }
  69.  
  70.         void RemoveStudent(List<Student> student)
  71.         {
  72.             for(int i = 0; i < student.Count(); i++){
  73.                 if(student[i].AttendancePercent == 0)
  74.                 {
  75.                     student.RemoveAt(i);
  76.                 }
  77.             }
  78.         }
  79.  
  80.         static void Main(string[] args)
  81.         {
  82.             List<Student> students = RetriveStudentsFromISVU();
  83.             int totalStudents = students.Count();
  84.             RemoveStudent(students);
  85.             int newTotal = students.Count();
  86.             if ((totalStudents - newTotal) > totalStudents / 2){
  87.                 Console.WriteLine("Studenata kojih nikad nije bilo je manje od pola.");
  88.             }
  89.             else
  90.             {
  91.                 Console.WriteLine("Studenata kojih nikad nije bilo je vise od pola.");
  92.             }
  93.         }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement