public static string studentReport(List <Student> students)
        {
            int    fullTime   = 0;
            int    distance   = 0;
            string ftStudents = String.Empty;
            string dtStudents = String.Empty;

            foreach (Student item in students)
            {
                if (item is FullTimeStudent)
                {
                    FullTimeStudent fts = (FullTimeStudent)item;
                    fullTime++;
                    ftStudents += $"{fts.getId()}\t{fts.getFirstName()}\t{fts.getLectureHours()}\t{fts.getCampus()}\n";
                }

                else if (item is DistanceStudent)
                {
                    DistanceStudent dts = (DistanceStudent)item;
                    distance++;
                    dtStudents += $"{dts.getId()}\t{dts.getFirstName()}\t{dts.getLectureHours()}\t{dts.getFacilitator()}\n";
                }
            }

            return($"There are {fullTime} Full Time Students\nThere are {distance} Part Time Students\n\nFULL TIME STUDENTS:\n{ftStudents}\n\nPART TIME STUDENTS:\n{dtStudents}");
        }
Beispiel #2
0
        static void addStudent(int selection)
        {
            Console.Write("STUDENT ID     >> ");
            string id = Console.ReadLine();

            Console.Write("FIRST NAME     >> ");
            string fName = Console.ReadLine();

            Console.Write("LAST NAME      >> ");
            string lName = Console.ReadLine();

            FileWorker fw = new FileWorker(filename);

            if (selection == 0)
            {
                Console.Write("CAMPUS         >> ");
                string          campus = Console.ReadLine();
                FullTimeStudent fts    = new FullTimeStudent(id, fName, lName, true, campus);
                ListHolder.addStudent(fts);
                fw.addToFile(StudentFormatter.formatForWrite(fts));
            }
            else
            {
                Console.Write("FACILITATOR    >> ");
                string          facilitator = Console.ReadLine();
                DistanceStudent dts         = new DistanceStudent(id, fName, lName, true, facilitator);
                ListHolder.addStudent(dts);
                fw.addToFile(StudentFormatter.formatForWrite(dts));
            }

            System.Console.WriteLine($"Student with id {id} added");
            System.Console.WriteLine("Press any key to go back ...");
            Console.ReadKey();
            addStudentMenu();
        }
 public static string formatForWrite(Student stIn)
 {
     if (stIn is FullTimeStudent)
     {
         FullTimeStudent fts = (FullTimeStudent)stIn;
         return($"F#{fts.getId()}#{fts.getFirstName()}#{fts.getLastName()}#{fts.getCampus()}");
     }
     else if (stIn is DistanceStudent)
     {
         DistanceStudent dts = (DistanceStudent)stIn;
         return($"D#{dts.getId()}#{dts.getFirstName()}#{dts.getLastName()}#{dts.getFacilitator()}");
     }
     else
     {
         return($"E#{stIn.getId()}");
     }
 }
Beispiel #4
0
        public List <Student> readFile()
        {
            List <Student> students = new List <Student>();

            if (new FileInfo(filename).Length > 0)
            {
                string[] lines = File.ReadAllLines(filename);
                if (lines.Length > 0)
                {
                    foreach (string line in lines)
                    {
                        string[] record = line.Split('#');

                        if (record[0].Equals("F"))
                        {
                            string id     = record[1];
                            string fName  = record[2];
                            string lName  = record[3];
                            string campus = record[4];

                            FullTimeStudent fts = new FullTimeStudent(id, fName, lName, true, campus);
                            students.Add(fts);
                        }
                        if (record[0].Equals("D"))
                        {
                            string id          = record[1];
                            string fName       = record[2];
                            string lName       = record[3];
                            string facilitator = record[4];

                            DistanceStudent dts = new DistanceStudent(id, fName, lName, true, facilitator);
                            students.Add(dts);
                        }
                    }
                }
            }



            return(students);
        }