Exemplo n.º 1
0
    static void Main()
    {
        List<Student> students = new List<Student>();

        Student c1 = new Student("Fred");
        Student c2 = new GradStudent("Elvis");
        Student c3 = new UndergradStudent("Callie");

        students.Add(c1);
        students.Add(c2);
        students.Add(c3);

        // Let's now pull them back out!
        for (int i=0; i < students.Count; i++) {
          Console.WriteLine(students[i].printMessage());
        }
    }
Exemplo n.º 2
0
    static void Main()
    {
        List <Student> students = new List <Student>();

        Student c1 = new Student("Fred");
        Student c2 = new GradStudent("Elvis");
        Student c3 = new UndergradStudent("Callie");

        students.Add(c1);
        students.Add(c2);
        students.Add(c3);

        // Let's now pull them back out!
        for (int i = 0; i < students.Count; i++)
        {
            Console.WriteLine(students[i].printMessage());
        }
    }
Exemplo n.º 3
0
        public static UndergradStudent AddUnderGradStudent(List <User> gList)
        {
            string         sName;
            float          gpa;
            string         DoB;
            string         PrevHSchool;
            Classification stdClass;

            Console.Write("Enter Name: ");
            sName = Console.ReadLine();

            Console.Write("Enter GPA: ");
            gpa = float.Parse(Console.ReadLine());

            Console.Write("Enter Date Of Birth: ");
            DoB = Console.ReadLine();

            Console.Write("Previous HighSchool: ");
            PrevHSchool = Console.ReadLine();

            Console.Write("Enter Classification: ");
            /* Menu? 1 == freshman? */
            stdClass = (Classification)Convert.ToInt32(Console.ReadLine());

            UndergradStudent output = new UndergradStudent(sName, gpa, DoB, PrevHSchool, stdClass);

            string uid = output.getUid();

            if (findUser(gList, uid) == null)
            {
                gList.Add(output);
                return(output);
            }

            return(null);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            char              ch, ch2;
            bool              successLogin = false;
            GradStudent       st;
            var               admins        = new List <User>();
            List <Course>     coursesList   = new List <Course>();
            List <Enrollment> courseEnrolls = new List <Enrollment>();



            List <User> profList = new List <User>();
            List <User> gslist   = new List <User>();
            List <User> ugslist  = new List <User>();



            LoadUserData('G', gslist, "GsList.txt");
            LoadUserData('U', ugslist, "UGsList.txt");
            LoadUserData('P', profList, "profData.txt");
            LoadCourseData(coursesList, "coursesData.txt");
            LoadUserData('A', admins, "adminData.txt");

            List <User> students = new List <User>();

            students.AddRange(gslist);
            students.AddRange(ugslist);


            do
            {
                ch = LoginMenu();

                switch (ch)
                {
                case '1':

                    Console.WriteLine("\n \t Enter your Id:");
                    string tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //1- Add Grad student" , "2- Add undergrad student", "3- List All grad students",
                            //"4- List All undergrad students", "5- Add new course", "6- list students in course");
                            ch2 = admin.Menu();
                            switch (ch2)
                            {
                            //TODO (1): Add new Grad Student
                            case '1':
                                //Get student info
                                Console.Write("\nEnter the graduate student's ID number: ");
                                string gradID = Console.ReadLine();
                                Console.Write("\nEnter the graduate student's password: "******"\nEnter the graduate student's name: ");
                                string gradStudentName = Console.ReadLine();
                                Console.Write("\nEnter the graduate student's GPA: ");
                                string gradStudentGPA = Console.ReadLine();
                                Console.Write("\nEnter the graduate student's date of birth: ");
                                string gradStudentDOB = Console.ReadLine();
                                Console.Write("\nEnter the graduate student's previous university: ");
                                string gradStudentPrevUni = Console.ReadLine();
                                Console.Write("\nEnter the graduate student's undergradutate GPA: ");
                                string gradStudentUnderGPA = Console.ReadLine();
                                break;
                                //Check to see if student exists
                                var gstudentCheck = findUser(gslist, gradID); //checking the id against students
                                if (gstudentCheck != null)                    //If student id already exists throw an error
                                {
                                    Console.WriteLine("\nError. A student with that ID already exists in the system.\n");
                                }
                                else
                                {
                                    //make a string for the GradStudent() function
                                    string[]    graduateStudent = new string[] { gradID, gradPassWord, gradStudentName, gradStudentGPA, gradStudentDOB, gradStudentPrevUni, gradStudentUnderGPA };
                                    GradStudent gstudent        = new GradStudent(graduateStudent);
                                    gslist.Add(gstudent);
                                }
                                break;

                            //TODO (2): Add new undergrad Student,
                            case '2':
                                //Get student info
                                Console.Write("\nEnter the undergraduate student's ID number: ");
                                string ugradID = Console.ReadLine();
                                Console.Write("\nEnter the undergraduate student's password: "******"\nEnter the undergraduate student's name: ");
                                string ugradStudentName = Console.ReadLine();
                                Console.Write("\nEnter the undergraduate student's GPA: ");
                                string ugradStudentGPA = Console.ReadLine();
                                Console.Write("\nEnter the undergraduate student's date of birth: ");
                                string ugradStudentDOB = Console.ReadLine();
                                Console.Write("\nEnter the undergraduate student's previous high school: ");
                                string ugradStudentPrevHS = Console.ReadLine();
                                Console.Write("\nEnter the undergraduate student's classification: ");
                                string ugradStudentClass = Console.ReadLine();
                                break;
                                //Check to see if student exists
                                var ugstudentCheck = findUser(gslist, gradID); //checking the id against students
                                if (ugstudentCheck != null)                    //If student id already exists throw an error
                                {
                                    Console.WriteLine("\nError. A student with that ID already exists in the system.\n");
                                }
                                else
                                {
                                    //make a string for the UndergradStudent() function
                                    string[]         undergraduateStudent = new string[] { ugradID, ugradPassWord, ugradStudentName, ugradStudentGPA, ugradStudentDOB, ugradStudentPrevHS, ugradStudentClass };
                                    UndergradStudent ugstudent            = new UndergradStudent(undergraduateStudent);
                                    ugslist.Add(ugstudent);
                                }
                                break;

                            case '3':
                                foreach (GradStudent std in gslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '4':
                                foreach (UndergradStudent std in ugslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '5':         //TODO (3): Add new  course by asking Admin for course info., verify inputs 1st
                                              //        : ++ Save new list to File if admin agrees
                                //Get input from user about course
                                Console.Write("\nEnter course's name: ");
                                string courseName = Console.ReadLine();
                                Console.Write("\nEnter course's ID: ");
                                int courseID = Convert.ToInt32(Console.ReadLine());
                                Console.Write("\nEnter amount of credits for this course: ");
                                var courseCreditsNum = Console.ReadLine();
                                //Check to see if the course already exists
                                var courseCheck = findCourse(coursesList, courseID); //checking the id against current courses
                                if (courseCheck != null)                             //If course id already exists throw an error
                                {
                                    Console.WriteLine("\nError. A course with that ID already exists in the system.\n");
                                }
                                else
                                {
                                    //make a string for the Course() function
                                    string   newCourseID  = Convert.ToString(courseID);
                                    string[] newCourse    = new string[] { courseName, newCourseID, courseCreditsNum };
                                    Course   addNewCourse = new Course(newCourse);
                                    coursesList.Add(addNewCourse);
                                }

                                // Test: Currently adding one specific course
                                // coursesList.Add(new Course("Adv. Prog", 3312, 3));
                                //coursesList[0].professor = (Professor )profList[0];
                                break;

                            case '6':         //TODO (4): Assign course to prof by getting ProfId, courseId,
                                              //        : verify inputs, and prof doesnot have >3 courses
                                              //        : ++ Save new list to File, and make the code initialize prof-course-assignment list from a file
                                //creating a loop so that the admin can correctly choose the professor and course id
                                string adminVerify = "N";
                                while (adminVerify != "Y")
                                {
                                    //Showing the admin the list of professors then making them chose by the professor ID
                                    Console.WriteLine("\nList of Professors");
                                    foreach (var p in profList)
                                    {
                                        string profID;
                                        Console.WriteLine($"Professor ID: {profID = p.getUid()}");
                                    }
                                    Console.Write("\nSelect a professor from the list above by typing the ID: ");
                                    string adminProfChoice = Console.ReadLine();
                                    //Checking that the selected professor exists
                                    Professor checkingProfSelection = (Professor)findUser(profList, adminProfChoice);
                                    //Showing the admin the list of courses then making them chose by the course ID
                                    Console.WriteLine("\nList of Courses");
                                    foreach (var c in coursesList)
                                    {
                                        int courseChoiceID;
                                        Console.WriteLine($"Course ID: {courseChoiceID= c.cId}");
                                    }
                                    Console.Write("\nSelect a course from the list above by typing the ID: ");
                                    string adminCourseChoice = Console.ReadLine();
                                    //Checking that the selected professor exists
                                    Course checkingCourseSelection = (Course)findCourse(coursesList, Convert.ToInt32(adminCourseChoice));
                                    Console.Write($"\nAre these choices correct? (Y or N)\n\tProfessor ID = {adminProfChoice}\n\tCourse ID = {adminCourseChoice}");
                                    adminVerify = Console.ReadLine();

                                    if (adminVerify == "Y")
                                    {
                                        Console.WriteLine("\nChecking to see if the selected professor has more than three courses....");
                                        int numProfCourses = 0;
                                        foreach (var c in coursesList)
                                        {
                                            if (c.professor.getUid() == adminProfChoice)
                                            {
                                                numProfCourses++;         //Counts number of courses the selected professor has
                                            }
                                        }
                                        if (numProfCourses > 3)
                                        {
                                            Console.WriteLine("\nThis professor already has 3 courses. Please try again.");
                                            adminVerify = "N";
                                        }
                                        else
                                        {
                                            Console.WriteLine("\nAssigning the course to the professor...");
                                            foreach (var c in coursesList)
                                            {
                                                if (c.cId == Convert.ToInt32(adminCourseChoice))
                                                {
                                                    c.professor = checkingProfSelection;
                                                    c.professor.addCourseToTeach(c);
                                                    Console.WriteLine("\nCourse successfully.");
                                                }
                                            }
                                        }
                                    }
                                }

                                // Test: Currently Assign all courses to 1st prof in the list
                                // foreach (var c in coursesList)
                                // {
                                //     c.professor = (Professor)profList[0];
                                //     c.professor.addCourseToTeach(c);
                                // }
                                break;

                            case '7':
                                foreach (var std in courseEnrolls)
                                {
                                    std.displEnrolledStudInfo();
                                }
                                break;
                            } //end switch ch2
                        } while (ch2 != '0');
                    }         // else



                    break;

                case '2':      //  Works for both grad & undergrad using student combined list
                case '3':
                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //"1- List My courses", "2- Enroll in a course","3- submit course Assesment"
                            ch2 = student.Menu();
                            switch (ch2)
                            {
                            case '1':
                                student.DisplayEnrollments();

                                break;

                            case '2':
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (5): check if stud already enrolled in the course before adding
                                Enrollment courseChecking;
                                courseChecking = student.getEnrolmentByCourseId(cId);
                                if (courseChecking != null)
                                {
                                    Console.WriteLine("/nStudent is already enrolled in this course.");
                                }
                                else
                                {
                                    if (selectedCourse != null)
                                    {
                                        Enrollment tEn = new Enrollment(selectedCourse, student);
                                        courseEnrolls.Add(tEn);
                                        student.addEnrollment(tEn);
                                        selectedCourse.addEnrollment(tEn);
                                    }
                                }
                                break;


                            case '3':
                                student.DisplayEnrollments();
                                Console.WriteLine("Select Course Id To submit Assessment for: ");

                                cId = int.Parse(Console.ReadLine());

                                //selectedCourse = findCourse(coursesList,  cId);
                                //
                                Enrollment e = student.getEnrolmentByCourseId(cId);
                                if (e != null)
                                {
                                    e.getCourse().displayCourseAssessments();
                                    Console.WriteLine("Select Assessment Id To submit: ");
                                    string assessId = Console.ReadLine().Trim();
                                    e.submitAssesment(assessId, "12/12/2018");
                                }
                                break;

                            case '4':
                                // TODO (6): Drop course, get cId, verify cId in student enrollments, then remove enrollment.
                                Console.WriteLine("Enter Course Id for course to drop: ");
                                int cDropId = int.Parse(Console.ReadLine());

                                Course selectedDropCourse = findCourse(coursesList, cDropId);
                                // TODO (5): check if stud already enrolled in the course before adding
                                Enrollment courseCheckingForDrop;
                                courseCheckingForDrop = student.getEnrolmentByCourseId(cDropId);
                                if (courseCheckingForDrop != null)
                                {
                                    courseEnrolls.Remove(courseCheckingForDrop);
                                    Console.WriteLine("\nStudent has been dropped from the course.");
                                }
                                else
                                {
                                    Console.WriteLine("\nStudent already not enrolled.");
                                }
                                break;
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;

                case '4':     //prof

                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            // 1- List my courses, 2- Add Assesment to course,3- Update student's Assesment points");
                            // 4- list students in a course
                            ch2 = prof.Menu();
                            switch (ch2)
                            {
                            case '1':
                                prof.displayCourses();
                                break;

                            case '2':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (7): get assessment type: assignment, exam, proj,...
                                //         : then add assessment info
                                Console.Write("\nEnter the type of assesmment: 1 - assignment, 2 - exam");
                                string assesmentType = Console.ReadLine();
                                switch (assesmentType)
                                {
                                case "1":
                                    if (selectedCourse != null)
                                    {
                                        Console.WriteLine("Enter Assessment info: ");
                                        Console.WriteLine("Id = ");
                                        string assesId = Console.ReadLine();
                                        Console.WriteLine("Weight = ");
                                        float aPercent = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Descr = ");
                                        string asDescr = Console.ReadLine();
                                        Console.WriteLine("Points = ");
                                        float aPoints = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Due on = ");
                                        string aDueDate = Console.ReadLine();
                                        Console.WriteLine("Late Pen = ");
                                        float latePen = float.Parse(Console.ReadLine());

                                        selectedCourse.AddCourseAssesment(new Assignment(assesId, aPercent, asDescr, aPoints, aDueDate, latePen));
                                    }
                                    break;

                                case "2":
                                    if (selectedCourse != null)
                                    {
                                        Console.WriteLine("Enter Assessment info: ");
                                        Console.WriteLine("Exam Name = ");
                                        string examName = Console.ReadLine();
                                        Console.WriteLine("Exam Percentage = ");
                                        float examPercentage = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Exam Points = ");
                                        float examPoints = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Exam Due On = ");
                                        string examDueDate = Console.ReadLine();
                                        Console.WriteLine("Exam Number of Attempts = ");
                                        int examAttempts = int.Parse(Console.ReadLine());
                                        selectedCourse.AddCourseAssesment(new Exam(examName, examPercentage, examPoints, examDueDate, examAttempts));
                                    }
                                    break;
                                }


                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW1",0.25f,"written assignment",200,"10/22/18",0.1f));
                                //coursesList[0].AddCourseAssesmsnt(new Exam("MT",0.50f, 200,"10/22/18",2));
                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW2",0.25f,"written assignment",300,"10/22/18",0.1f));

                                break;

                            case '3':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                    Console.WriteLine("Select student name  ");
                                    //Console.WriteLine(" sName : ");
                                    string sName = Console.ReadLine().Trim();

                                    Student s = selectedCourse.getStudentByName(sName);

                                    Enrollment e = s.getEnrolmentByCourseId(cId);
                                    if (e != null)
                                    {
                                        e.getCourse().displayCourseAssessments();
                                        Console.WriteLine("Select Assessment Id To update: ");
                                        string         assessId       = Console.ReadLine().Trim();
                                        StudAssessment studAssessment = e.getStudAssessmentById(assessId);
                                        Console.WriteLine("Enter assessment Points :");
                                        float newPoints = float.Parse(Console.ReadLine());
                                        studAssessment.updateAssessmentPoints(newPoints);
                                    }
                                }
                                break;

                            case '4':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                }
                                break;
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;
                }// switch ch
            } while (ch != '0');
        }
        //find all undergraduate students, graduate students, faculty, and chairpersons
        //creates an instance of each class
        public void createOwlMemberList()
        {
            using (OleDbConnection connection = new OleDbConnection(strConnection))
            {
                try
                {
                    connection.Open();

                    using (OleDbCommand command1 = new OleDbCommand("SELECT OWLMEMBER.fldID, OWLMEMBER.fldName, OWLMEMBER.fldBirthDate, "
                                                                    + "STUDENT.fldMajor, STUDENT.fldGPA "
                                                                    + "FROM (OWLMEMBER INNER JOIN STUDENT ON OWLMEMBER.fldID = STUDENT.fldID);", connection))
                    {
                        OleDbDataReader reader = command1.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int      id      = reader.GetInt32(0);
                                string   name    = reader.GetString(1);
                                DateTime bday    = reader.GetDateTime(2);
                                string   major   = reader.GetString(3);
                                decimal  gpa     = reader.GetDecimal(4);
                                Student  student = new Student(id, name, bday, major, gpa);
                                //GlobalData.owlList.addToList(student);
                            }
                        }
                    }

                    using (OleDbCommand command2 = new OleDbCommand("SELECT OWLMEMBER.fldID, OWLMEMBER.fldName, OWLMEMBER.fldBirthDate, "
                                                                    + "STUDENT.fldMajor, STUDENT.fldGPA, "
                                                                    + "UNDERGRADUATESTUDENT.fldTuition, UNDERGRADUATESTUDENT.fldYear, UNDERGRADUATESTUDENT.fldCredits "
                                                                    + "FROM (OWLMEMBER INNER JOIN STUDENT ON OWLMEMBER.fldID = STUDENT.fldID) INNER JOIN UNDERGRADUATESTUDENT ON STUDENT.fldID = UNDERGRADUATESTUDENT.fldID;", connection))
                    {
                        OleDbDataReader reader = command2.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int              id      = reader.GetInt32(0);
                                string           name    = reader.GetString(1);
                                DateTime         bday    = reader.GetDateTime(2);
                                string           major   = reader.GetString(3);
                                decimal          gpa     = reader.GetDecimal(4);
                                decimal          tuition = reader.GetDecimal(5);
                                string           year    = reader.GetString(6);
                                int              credits = reader.GetInt32(7);
                                UndergradStudent UG      = new UndergradStudent(id, name, bday, major, gpa, tuition, year, credits);
                                //GlobalData.owlList.addToList(UG);
                            }
                        }
                    }
                    using (OleDbCommand command3 = new OleDbCommand("SELECT OWLMEMBER.fldID, OWLMEMBER.fldName,OWLMEMBER.fldBirthdate, "
                                                                    + "STUDENT.fldMajor, STUDENT.fldGPA, "
                                                                    + "GRADUATESTUDENT.fldDegreeProgram, GRADUATESTUDENT.fldStipend "
                                                                    + "FROM (OWLMEMBER INNER JOIN STUDENT ON OWLMEMBER.fldID = STUDENT.fldID) INNER JOIN GRADUATESTUDENT ON STUDENT.fldID = GRADUATESTUDENT.fldID;", connection))
                    {
                        OleDbDataReader reader = command3.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())

                            {
                                int         id      = reader.GetInt32(0);
                                string      name    = reader.GetString(1);
                                DateTime    bday    = reader.GetDateTime(2);
                                string      major   = reader.GetString(3);
                                decimal     gpa     = reader.GetDecimal(4);
                                string      program = reader.GetString(5);
                                decimal     stipend = reader.GetDecimal(6);
                                GradStudent GS      = new GradStudent(id, name, bday, major, gpa, program, stipend);
                                // GlobalData.owlList.addToList(GS);
                            }
                        }
                    }
                    using (OleDbCommand command4 = new OleDbCommand("SELECT OWLMEMBER.fldID, OWLMEMBER.fldName, OWLMEMBER.fldBirthDate, "
                                                                    + "FACULTY.fldDepartment, FACULTY.fldRank "
                                                                    + "FROM OWLMEMBER INNER JOIN FACULTY ON OWLMEMBER.fldID = FACULTY.fldId;", connection))
                    {
                        OleDbDataReader reader = command4.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())

                            {
                                int      id     = reader.GetInt32(0);
                                string   name   = reader.GetString(1);
                                DateTime bday   = reader.GetDateTime(2);
                                string   dept   = Convert.ToString(reader.GetTextReader(3));
                                string   rank   = Convert.ToString(reader.GetTextReader(4));
                                Faculty  member = new Faculty(id, name, bday, dept, rank);
                                //GlobalData.owlList.addToList(member);
                            }
                        }
                    }
                    using (OleDbCommand command5 = new OleDbCommand("SELECT OWLMEMBER.fldID, OWLMEMBER.fldName,OWLMEMBER.fldBirthdate, "
                                                                    + "FACULTY.fldDepartment, FACULTY.fldRank, CHAIRPERSON.fldStipend "
                                                                    + "FROM (OWLMEMBER INNER JOIN FACULTY ON OWLMEMBER.fldID = FACULTY.fldId) INNER JOIN CHAIRPERSON ON FACULTY.fldID = CHAIRPERSON.fldID;", connection))
                    {
                        OleDbDataReader reader = command5.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())

                            {
                                int         id      = reader.GetInt32(0);
                                string      name    = reader.GetString(1);
                                DateTime    bday    = reader.GetDateTime(2);
                                string      dept    = reader.GetString(3);
                                string      rank    = reader.GetString(4);
                                decimal     stipend = reader.GetDecimal(5);
                                Chairperson chair   = new Chairperson(id, name, bday, dept, rank, stipend);
                                //GlobalData.owlList.addToList(chair);
                            }
                        }
                    }
                    connection.Close();
                }
                catch (OleDbException ex)
                {
                    Console.Write("Error: " + ex.Message);
                    connection.Close();
                }
            }
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            char              ch, ch2;
            bool              successLogin = false;
            GradStudent       st;
            var               admins        = new List <User>();
            List <Course>     coursesList   = new List <Course>();
            List <Enrollment> courseEnrolls = new List <Enrollment>();



            List <User> profList = new List <User>();
            List <User> gslist   = new List <User>();
            List <User> ugslist  = new List <User>();



            LoadUserData('G', gslist, "GsList.txt");
            LoadUserData('U', ugslist, "UGsList.txt");
            LoadUserData('P', profList, "profData.txt");
            LoadCourseData(coursesList, "coursesData.txt");
            LoadUserData('A', admins, "adminData.txt");

            List <User> students = new List <User>();

            students.AddRange(gslist);
            students.AddRange(ugslist);


            do
            {
                ch = LoginMenu();

                switch (ch)
                {
                case '1':

                    Console.WriteLine("\n \t Enter your Id:");
                    string tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //1- Add Grad student" , "2- Add undergrad student", "3- List All grad students",
                            //"4- List All undergrad students", "5- Add new course", "6- list students in course");
                            ch2 = admin.Menu();
                            switch (ch2)
                            {
                            //TODO (1): Add new Grad Student
                            case '1':
                                Console.Write("\nEnter  User ID number: ");
                                string Id = Console.ReadLine();
                                Console.Write("\nEnter  password: "******"\nEnter  name: ");
                                string sName = Console.ReadLine();
                                Console.Write("\nEnter  date of birth: ");
                                string DoB = Console.ReadLine();
                                Console.Write("\nEnter your student ID: ");
                                string sId = Console.ReadLine();
                                Console.Write("\nEnter GPA: ");
                                string GPA = Console.ReadLine();
                                Console.Write("\nEnter previous degree: ");
                                string pDeg = Console.ReadLine();
                                Console.Write("Enter the previous University:");
                                string pUni = Console.ReadLine();
                                Console.WriteLine("Enter department:");
                                string Dept = Console.ReadLine();
                                Console.Write("Enter UnderGrad GPA:");
                                string    uGPA        = Console.ReadLine();
                                string [] gradStudent = new string [] { Id, pw, sName, sId, DoB, Dept, GPA, pDeg, pUni, uGPA };
                                var       rUser       = findUser(gslist, Id);
                                if (rUser != null)
                                {
                                    Console.WriteLine("ID is already in use");
                                    break;
                                }
                                else
                                {
                                    gslist.Add(st = new GradStudent(gradStudent));
                                    Console.WriteLine("\n Graduate student has been added");
                                    break;
                                }

                            //TODO (2): Add new undergrad Student,
                            case '2':

                                Console.Write("Enter your User ID: ");
                                Id = Console.ReadLine();
                                Console.Write("Enter your password: "******"Enter your name: ");
                                sName = Console.ReadLine();
                                Console.Write("Enter your date of birth: ");
                                DoB = Console.ReadLine();
                                Console.Write("Enter your student ID: ");
                                sId = Console.ReadLine();
                                Console.Write("Enter your department: ");
                                Dept = Console.ReadLine();
                                Console.Write("Enter your GPA: ");
                                GPA = Console.ReadLine();
                                Console.Write("Enter your High School: ");
                                string HS = Console.ReadLine();
                                Console.Write("Enter your student classification: ");
                                string   Class        = Console.ReadLine();
                                string[] uGradStudent = new string[] { Id, pw, sName, sId, DoB, Dept, GPA, HS, Class };
                                rUser = findUser(ugslist, Id);
                                if (rUser != null)
                                {
                                    Console.WriteLine("ID is already is use");
                                }
                                else
                                {        //Check for student, then add student
                                    Student nStu = new UndergradStudent(uGradStudent);
                                    foreach (var s in courseEnrolls)
                                    {
                                        var rStd = s.getStudent();
                                        if (nStu.getUid() == rStd.getUid())
                                        {
                                            Console.WriteLine("Student is already enrolled in this class");
                                            break;
                                        }
                                    }
                                    ugslist.Add(nStu);
                                    Console.WriteLine("\n Student has been added");
                                }

                                break;

                            case '3':
                                foreach (GradStudent std in gslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '4':
                                foreach (UndergradStudent std in ugslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '5':         //TODO (3): Add new  course by asking Admin for course info., verify inputs 1st
                                              //        : ++ Save new list to File if admin agrees
                                Console.Write("Enter course ID:");
                                var cid = Console.ReadLine();
                                Console.Write("Enter Course name");
                                var cN = Console.ReadLine();
                                Console.Write("Enter amount of credits");
                                var      credits = Console.ReadLine();
                                string[] course  = new string[] { cN, cid, credits };
                                Console.WriteLine("Is the information correct? y/n");
                                foreach (var i in course)
                                {
                                    Console.WriteLine(i);
                                }
                                Console.WriteLine("Is information correct? y/n");
                                var answer = Console.ReadLine();
                                switch (answer)
                                {
                                case "y":
                                case "Y":
                                    //if information is correct add course to course list
                                    coursesList.Add(new Course(course[0], Int32.Parse(course[1]), Int32.Parse(course[2])));
                                    Console.WriteLine("\nThe Course has been added to the list");
                                    //Extra Credit
                                    Console.WriteLine("Would you like to save updates to the course data file? y/n ");
                                    answer = Console.ReadLine();
                                    switch (answer)
                                    {
                                    case "y":
                                    case "Y":
                                        var output = $"\n{course[0]}, {course[1]}, {course[2]}";
                                        System.IO.File.AppendAllText(@"coursesData.txt", output);
                                        break;

                                    case "n":
                                    case "N":
                                        Console.WriteLine("Course was not saved to the data file.");
                                        break;

                                    default:
                                        Console.WriteLine("There was an error");
                                        break;
                                    }
                                    break;

                                case "n":
                                case "N":
                                    Console.WriteLine("\nCourse information was not added.");
                                    break;

                                default:
                                    break;

                                    // Test: Currently adding one specific course

                                    //coursesList[0].professor = (Professor )profList[0];
                                }
                                coursesList.Add(new Course("Adv. Prog", 3312, 3));
                                break;


                            case '6':         //TODO (4): Assign course to prof by getting ProfId, courseId,
                                              //        : verify inputs, and prof doesnot have >3 courses
                                              //        : ++ Save new list to File, and make the code initialize prof-course-assignment list from a file

                                // Test: Currently Assign all courses to 1st prof in the list
                                foreach (var c in coursesList)
                                {
                                    c.professor = (Professor)profList[0];
                                    c.professor.addCourseToTeach(c);
                                }
                                //Show the list of Professors
                                Console.WriteLine("---Professor List---");
                                string uId;

                                foreach (var i in profList)
                                {
                                    uId = i.getUid();
                                    Console.WriteLine(uId);
                                }

                                Console.WriteLine("Enter Professor ID");
                                var profId = Console.ReadLine();

                                //Showing the list of courses
                                Console.WriteLine("--Course List--");
                                int crsID;
                                foreach (var c in coursesList)
                                {
                                    crsID = c.cId;
                                    Console.WriteLine(crsID);
                                }
                                Console.WriteLine("\n Enter Course ID");
                                var courseId = Int32.Parse(Console.ReadLine());
                                //Verifying Professor information against Course information
                                Professor prCheck = (Professor)findUser(profList, profId);
                                Course    crCheck = (Course)findCourse(coursesList, courseId);
                                //check
                                if (prCheck == null)
                                {
                                    Console.WriteLine("Professor ID was not found or assigned to the course");
                                    break;
                                }
                                else if (crCheck == null)
                                {
                                    Console.WriteLine("Course ID was not found Professor was not assigned to this course");
                                    break;
                                }
                                int pfCount = 0;
                                foreach (var c in coursesList)
                                {
                                    if (c.professor.getUid() == profId)
                                    {
                                        pfCount++;
                                    }
                                }
                                if (pfCount > 3)
                                {
                                    Console.WriteLine("The Professor is assigned to more than 3 courses\n Professor is not assigned to this course ");
                                    break;
                                }
                                else
                                {
                                    foreach (var c in coursesList)
                                    {
                                        if (courseId == c.cId)
                                        {
                                            c.professor = prCheck;
                                            c.professor.addCourseToTeach(c);
                                            Console.WriteLine($"The professor with the id {profId} was assigned to {courseId} ");
                                            //Extra credit
                                            Console.Write("Would you like to save the course assignment to a file? y/n");
                                            var saveIt = Console.ReadLine();
                                            switch (saveIt)
                                            {
                                            case "y":
                                            case "Y":
                                                var info = $"{profId}, {courseId}";
                                                System.IO.File.AppendAllText
                                                    (@"courseProfAssignment.txt", info);
                                                Console.WriteLine("Professor course assignment was saved to coursesProfAssignment.txt");
                                                break;

                                            case "n":
                                            case "N":
                                                Console.WriteLine("Professor course assignment not saved to a file");
                                                break;

                                            default:
                                                Console.WriteLine("There was an error");
                                                break;
                                            }
                                        }
                                    }
                                }
                                break;

                            default:
                                break;

                            case '7':
                                foreach (var std in courseEnrolls)
                                {
                                    std.displEnrolledStudInfo();
                                }
                                break;
                            } //end switch ch2
                        } while (ch2 != '0');
                    }         // else



                    break;

                case '2':      //  Works for both grad & undergrad using student combined list
                case '3':
                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //"1- List My courses", "2- Enroll in a course","3- submit course Assesment"
                            ch2 = student.Menu();
                            switch (ch2)
                            {
                            case '1':
                                student.DisplayEnrollments();

                                break;

                            case '2':
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (5): check if stud already enrolled in the course before adding
                                if (selectedCourse != null)
                                {
                                    Enrollment tEn = new Enrollment(selectedCourse, student);
                                    courseEnrolls.Add(tEn);
                                    student.addEnrollment(tEn);
                                    selectedCourse.addEnrollment(tEn);
                                }
                                break;


                            case '3':
                                student.DisplayEnrollments();
                                Console.WriteLine("Select Course Id To submit Assessment for: ");

                                cId = int.Parse(Console.ReadLine());

                                //selectedCourse = findCourse(coursesList,  cId);
                                //
                                Enrollment e = student.getEnrolmentByCourseId(cId);
                                if (e != null)
                                {
                                    e.getCourse().displayCourseAssessments();
                                    Console.WriteLine("Select Assessment Id To submit: ");
                                    string assessId = Console.ReadLine().Trim();
                                    e.submitAssesment(assessId, "12/12/2018");
                                }
                                break;

                            case '4':
                                // TODO (6): Drop course, get cId, verify cId in student enrollments, then remove enrol.
                                Console.WriteLine("Drop Course-");
                                Console.Write("Enter the course ID");
                                var crsID  = Int32.Parse(Console.ReadLine());
                                var enroll = student.getEnrolmentByCourseId(crsID);
                                if (enroll != null)
                                {
                                    courseEnrolls.Remove(enroll);
                                    Console.WriteLine("\nThe Course has been dropped\n");
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("\nStudent not enrolled in course\n");
                                    break;
                                }
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;

                case '4':     //prof

                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            // 1- List my courses, 2- Add Assesment to course,3- Update student's Assesment points");
                            // 4- list students in a course
                            ch2 = prof.Menu();
                            switch (ch2)
                            {
                            case '1':
                                prof.displayCourses();
                                break;

                            case '2':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (7): get assessment type: assignment, exam, proj,...
                                //         : then add assessment info
                                Console.Write("Enter assessment type: exam or assignment");
                                var assessType = Console.ReadLine();
                                switch (assessType)
                                {
                                case "exam":
                                    Console.WriteLine("Enter assesment information");
                                    Console.Write("Name = ");
                                    var asName = Console.ReadLine();
                                    Console.Write("Percentage = ");
                                    var percentage = float.Parse(Console.ReadLine());
                                    Console.WriteLine("Total Points = ");
                                    var totPoints = float.Parse(Console.ReadLine());
                                    Console.Write("Due on = ");
                                    var duedate = Console.ReadLine();
                                    Console.Write("Number of attempts = ");
                                    var numofAttempts = Int32.Parse(Console.ReadLine());

                                    selectedCourse.AddCourseAssesment(new Exam(asName, percentage, totPoints, duedate, numofAttempts));
                                    break;

                                case "assignment":
                                    if (selectedCourse != null)
                                    {
                                        Console.WriteLine("Enter Assessment info: ");
                                        Console.WriteLine("Id = ");
                                        string assesId = Console.ReadLine();
                                        Console.WriteLine("Weight = ");
                                        float aPercent = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Descr = ");
                                        string asDescr = Console.ReadLine();
                                        Console.WriteLine("Points = ");
                                        float aPoints = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Due on = ");
                                        string aDueDate = Console.ReadLine();
                                        Console.WriteLine("Late Pen = ");
                                        float latePen = float.Parse(Console.ReadLine());

                                        selectedCourse.AddCourseAssesment(new Assignment(assesId, aPercent, asDescr, aPoints, aDueDate, latePen));
                                    }
                                    break;



                                default:
                                    Console.WriteLine("There was an error");
                                    break;
                                }

                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW1",0.25f,"written assignment",200,"10/22/18",0.1f));
                                //coursesList[0].AddCourseAssesmsnt(new Exam("MT",0.50f, 200,"10/22/18",2));
                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW2",0.25f,"written assignment",300,"10/22/18",0.1f));

                                break;

                            case '3':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                    Console.WriteLine("Select student name  ");
                                    //Console.WriteLine(" sName : ");
                                    string sName = Console.ReadLine().Trim();

                                    Student s = selectedCourse.getStudentByName(sName);

                                    Enrollment e = s.getEnrolmentByCourseId(cId);
                                    if (e != null)
                                    {
                                        e.getCourse().displayCourseAssessments();
                                        Console.WriteLine("Select Assessment Id To update: ");
                                        string         assessId       = Console.ReadLine().Trim();
                                        StudAssessment studAssessment = e.getStudAssessmentById(assessId);
                                        Console.WriteLine("Enter assessment Points :");
                                        float newPoints = float.Parse(Console.ReadLine());
                                        studAssessment.updateAssessmentPoints(newPoints);
                                    }
                                }
                                break;

                            case '4':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                }
                                break;
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;
                }// switch ch
            } while (ch != '0');
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            char             ch, ch2;
            bool             successLogin = false;
            GradStudent      st;
            UndergradStudent stu;
            var               admins        = new List <User>();
            List <Course>     coursesList   = new List <Course>();
            List <Enrollment> courseEnrolls = new List <Enrollment>();



            List <User> profList = new List <User>();
            List <User> gslist   = new List <User>();
            List <User> ugslist  = new List <User>();



            LoadUserData('G', gslist, "GsList.txt");
            LoadUserData('U', ugslist, "UGsList.txt");
            LoadUserData('P', profList, "profData.txt");
            LoadCourseData(coursesList, "coursesData.txt");
            LoadUserData('A', admins, "adminData.txt");

            List <User> students = new List <User>();

            students.AddRange(gslist);
            students.AddRange(ugslist);


            do
            {
                ch = LoginMenu();

                switch (ch)
                {
                case '1':

                    Console.WriteLine("\n \t Enter your Id:");
                    string tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //1- Add Grad student" , "2- Add undergrad student", "3- List All grad students",
                            //"4- List All undergrad students", "5- Add new course", "6- list students in course");
                            ch2 = admin.Menu();
                            switch (ch2)
                            {
                            //TODO (1): Add new Grad Student <<DONE>>
                            case '1':
                                Console.WriteLine("Please Enter an ID");
                                string Id = Console.ReadLine();
                                Console.WriteLine("Please Enter a Password");
                                string pswd = Console.ReadLine();
                                Console.WriteLine("Please Enter a Name");
                                string name = Console.ReadLine();
                                Console.WriteLine("Please Enter a Student ID");
                                string sID = Console.ReadLine();
                                Console.WriteLine("Please Enter a Date of Birth");
                                string doB = Console.ReadLine();
                                Console.WriteLine("Please Enter a Undergrad Department");
                                string uDept = Console.ReadLine();
                                Console.WriteLine("Please Enter a GPA");
                                string GPA = Console.ReadLine();
                                Console.WriteLine("Please Enter a Previous Degree");
                                string pDeg = Console.ReadLine();
                                Console.WriteLine("Please Enter a Previous University");
                                string pUni = Console.ReadLine();
                                Console.WriteLine("Please Enter a Graduate Department");
                                string GradDept = Console.ReadLine();
                                Console.WriteLine("Please Enter a Undergrad GPA");
                                string   uGPA          = Console.ReadLine();
                                string[] grad          = new string[] { Id, pswd, name, sID, doB, uDept, GPA, pDeg, pUni, GradDept, uGPA };
                                var      checkIfExists = findUser(gslist, Id);
                                if (checkIfExists != null)
                                {
                                    Console.WriteLine("They are already in the list");
                                    break;
                                }
                                else
                                {
                                    gslist.Add(st = new GradStudent(grad));
                                    Console.WriteLine("student added");
                                    break;
                                }

                            //TODO (2): Add new undergrad Student,
                            case '2':
                                Console.WriteLine("Please Enter an ID");
                                Id = Console.ReadLine();
                                Console.WriteLine("Please Enter a Password");
                                pswd = Console.ReadLine();
                                Console.WriteLine("Please Enter a Name");
                                name = Console.ReadLine();
                                Console.WriteLine("Please Enter a Student ID");
                                sID = Console.ReadLine();
                                Console.WriteLine("Please Enter a Date of Birth");
                                doB = Console.ReadLine();
                                Console.WriteLine("Please Enter a Undergrad Department");
                                uDept = Console.ReadLine();
                                Console.WriteLine("Please Enter a GPA");
                                GPA = Console.ReadLine();
                                Console.WriteLine("Please Enter a Highschool");
                                string highSchool = Console.ReadLine();
                                Console.WriteLine("Please Enter a Classification");
                                string   classification = Console.ReadLine();
                                string[] ugrad          = new string[] { Id, pswd, name, sID, doB, uDept, GPA, highSchool, classification };
                                var      checkIfExistsU = findUser(ugslist, Id);
                                if (checkIfExistsU != null)
                                {
                                    Console.WriteLine("They are already in the list");
                                    break;
                                }
                                else
                                {
                                    ugslist.Add(stu = new UndergradStudent(ugrad));
                                    Console.WriteLine("student added");
                                    break;
                                }

                            case '3':
                                foreach (GradStudent std in gslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '4':
                                foreach (UndergradStudent std in ugslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '5':         //TODO (3): Add new  course by asking Admin for course info., verify inputs 1st
                                              //        : ++ Save new list to File if admin agrees

                                // Test: Currently adding one specific course
                                coursesList.Add(new Course("Adv. Prog", 3312, 3));
                                //coursesList[0].professor = (Professor )profList[0];
                                break;

                            case '6':         //TODO (4): Assign course to prof by getting ProfId, courseId,
                                              //        : verify inputs, and prof doesnot have >3 courses
                                              //        : ++ Save new list to File, and make the code initialize prof-course-assignment list from a file

                                // Test: Currently Assign all courses to 1st prof in the list
                                foreach (var c in coursesList)
                                {
                                    c.professor = (Professor)profList[0];
                                    c.professor.addCourseToTeach(c);
                                }
                                break;

                            case '7':
                                foreach (var std in courseEnrolls)
                                {
                                    std.displEnrolledStudInfo();
                                }
                                break;
                            } //end switch ch2
                        } while (ch2 != '0');
                    }         // else



                    break;

                case '2':      //  Works for both grad & undergrad using student combined list
                case '3':
                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //"1- List My courses", "2- Enroll in a course","3- submit course Assesment"
                            ch2 = student.Menu();
                            switch (ch2)
                            {
                            case '1':
                                student.DisplayEnrollments();

                                break;

                            case '2':
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (5): check if stud already enrolled in the course before adding
                                if (selectedCourse != null)
                                {
                                    Enrollment tEn = new Enrollment(selectedCourse, student);
                                    courseEnrolls.Add(tEn);
                                    student.addEnrollment(tEn);
                                    selectedCourse.addEnrollment(tEn);
                                }
                                break;


                            case '3':
                                student.DisplayEnrollments();
                                Console.WriteLine("Select Course Id To submit Assessment for: ");

                                cId = int.Parse(Console.ReadLine());

                                //selectedCourse = findCourse(coursesList,  cId);
                                //
                                Enrollment e = student.getEnrolmentByCourseId(cId);
                                if (e != null)
                                {
                                    e.getCourse().displayCourseAssessments();
                                    Console.WriteLine("Select Assessment Id To submit: ");
                                    string assessId = Console.ReadLine().Trim();
                                    e.submitAssesment(assessId, "12/12/2018");
                                }
                                break;

                                //case '4':
                                // TODO (6): Drop course, get cId, verify cId in student enrollments, then remove enrol.
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;

                case '4':     //prof

                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            // 1- List my courses, 2- Add Assesment to course,3- Update student's Assesment points");
                            // 4- list students in a course
                            ch2 = prof.Menu();
                            switch (ch2)
                            {
                            case '1':
                                prof.displayCourses();
                                break;

                            case '2':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (7): get assessment type: assignment, exam, proj,...
                                //         : then add assessment info
                                if (selectedCourse != null)
                                {
                                    Console.WriteLine("Enter Assessment info: ");
                                    Console.WriteLine("Id = ");
                                    string assesId = Console.ReadLine();
                                    Console.WriteLine("Weight = ");
                                    float aPercent = float.Parse(Console.ReadLine());
                                    Console.WriteLine("Descr = ");
                                    string asDescr = Console.ReadLine();
                                    Console.WriteLine("Points = ");
                                    float aPoints = float.Parse(Console.ReadLine());
                                    Console.WriteLine("Due on = ");
                                    string aDueDate = Console.ReadLine();
                                    Console.WriteLine("Late Pen = ");
                                    float latePen = float.Parse(Console.ReadLine());

                                    selectedCourse.AddCourseAssesment(new Assignment(assesId, aPercent, asDescr, aPoints, aDueDate, latePen));
                                }


                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW1",0.25f,"written assignment",200,"10/22/18",0.1f));
                                //coursesList[0].AddCourseAssesmsnt(new Exam("MT",0.50f, 200,"10/22/18",2));
                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW2",0.25f,"written assignment",300,"10/22/18",0.1f));

                                break;

                            case '3':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                    Console.WriteLine("Select student name  ");
                                    //Console.WriteLine(" sName : ");
                                    string sName = Console.ReadLine().Trim();

                                    Student s = selectedCourse.getStudentByName(sName);

                                    Enrollment e = s.getEnrolmentByCourseId(cId);
                                    if (e != null)
                                    {
                                        e.getCourse().displayCourseAssessments();
                                        Console.WriteLine("Select Assessment Id To update: ");
                                        string         assessId       = Console.ReadLine().Trim();
                                        StudAssessment studAssessment = e.getStudAssessmentById(assessId);
                                        Console.WriteLine("Enter assessment Points :");
                                        float newPoints = float.Parse(Console.ReadLine());
                                        studAssessment.updateAssessmentPoints(newPoints);
                                    }
                                }
                                break;

                            case '4':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                }
                                break;
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;
                }// switch ch
            } while (ch != '0');
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            char              ch, ch2;
            bool              successLogin = false;
            GradStudent       st;
            var               admins        = new List <User>();
            List <Course>     coursesList   = new List <Course>();
            List <Enrollment> courseEnrolls = new List <Enrollment>();



            List <User> profList = new List <User>();
            List <User> gslist   = new List <User>();
            List <User> ugslist  = new List <User>();



            LoadUserData('G', gslist, "GsList.txt");
            LoadUserData('U', ugslist, "UGsList.txt");
            LoadUserData('P', profList, "profData.txt");
            LoadCourseData(coursesList, "coursesData.txt");
            LoadUserData('A', admins, "adminData.txt");

            List <User> students = new List <User>();

            students.AddRange(gslist);
            students.AddRange(ugslist);


            do
            {
                ch = LoginMenu();

                switch (ch)
                {
                case '1':

                    Console.WriteLine("\n \t Enter your Id:");
                    string tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //1- Add Grad student" , "2- Add undergrad student", "3- List All grad students",
                            //"4- List All undergrad students", "5- Add new course", "6- list students in course");
                            ch2 = admin.Menu();
                            switch (ch2)
                            {
                            //TODO (1): Add new Grad Student
                            case '1':
                                Console.WriteLine("Enter User ID: ");
                                string uid = Console.ReadLine();
                                Console.WriteLine("Enter Password: "******"Enter Student Name: ");
                                string sname = Console.ReadLine();
                                Console.WriteLine("Enter GPA: ");
                                string gpa = Console.ReadLine();
                                Console.WriteLine("Enter DoB: ");
                                string DoB = Console.ReadLine();
                                Console.WriteLine("Enter Previous University: ");
                                string PrevUniversity = Console.ReadLine();
                                Console.WriteLine("Enter Undergrad GPA: ");
                                string   ugGpa        = Console.ReadLine();
                                string[] inputStrings = new string[11] {
                                    uid, pw, sname, null, DoB, null, gpa, null, PrevUniversity, null, ugGpa
                                };
                                int existAlready = 0;
                                foreach (GradStudent g in gslist)
                                {
                                    if (g.getUid() == uid)
                                    {
                                        existAlready = 1;
                                    }
                                }
                                if (existAlready == 1)
                                {
                                    break;
                                }
                                GradStudent gradstudentk = new GradStudent(inputStrings);
                                break;

                            //TODO (2): Add new undergrad Student,
                            case '2':
                                Console.WriteLine("Enter User ID: ");
                                string uid2 = Console.ReadLine();
                                Console.WriteLine("Enter Password: "******"Enter Student Name: ");
                                string sname2 = Console.ReadLine();
                                Console.WriteLine("Enter GPA: ");
                                string gpa2 = Console.ReadLine();
                                Console.WriteLine("Enter DoB: ");
                                string DoB2 = Console.ReadLine();
                                Console.WriteLine("Enter High School: ");
                                string highschool = Console.ReadLine();
                                Console.WriteLine("Enter Class: ");
                                string   classif       = Console.ReadLine();
                                string[] inputStrings2 = new string[9] {
                                    uid2, pw2, sname2, null, DoB2, null, gpa2, highschool, classif
                                };
                                //File: uId, pw, sName, sID, DoB, Dept, GPA, HS, Class
                                //       0    1    2     3    4     5    6    7    8
                                int existAlready2 = 0;
                                foreach (UndergradStudent u in ugslist)
                                {
                                    if (u.getUid() == uid2)
                                    {
                                        existAlready = 1;
                                    }
                                }
                                if (existAlready2 == 1)
                                {
                                    break;
                                }
                                UndergradStudent ugradstudentk = new UndergradStudent(inputStrings2);
                                break;

                            case '3':
                                foreach (GradStudent std in gslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '4':
                                foreach (UndergradStudent std in ugslist)
                                {
                                    Console.WriteLine();
                                    std.DisplayStdInfo();
                                }
                                break;

                            case '5':         //TODO (3): Add new  course by asking Admin for course info., verify inputs 1st
                                              //        : ++ Save new list to File if admin agrees
                                Console.WriteLine("Enter Course Name: ");
                                string coursename = Console.ReadLine();
                                Console.WriteLine("Enter Course ID: ");
                                int id = Convert.ToInt16(Console.ReadLine());
                                Console.WriteLine("Enter Credits: ");
                                int credits            = Convert.ToInt16(Console.ReadLine());
                                int coursealreadyexist = 0;
                                foreach (Course x in coursesList)
                                {
                                    if (x.cId == id)
                                    {
                                        coursealreadyexist = 1;
                                    }
                                }
                                if (coursealreadyexist == 1)
                                {
                                    break;
                                }
                                Course coursse = new Course(coursename, id, credits);
                                coursesList.Add(coursse);
                                // Test: Currently adding one specific course
                                //coursesList.Add(new Course("Adv. Prog", 3312, 3));
                                //coursesList[0].professor = (Professor )profList[0];
                                break;

                            case '6':         //TODO (4): Assign course to prof by getting ProfId, courseId,
                                              //        : verify inputs, and prof doesnot have >3 courses
                                              //        : ++ Save new list to File, and make the code initialize prof-course-assignment list from a file
                                foreach (Professor m in profList)
                                {
                                    Console.WriteLine(m.getUid());
                                }
                                Console.WriteLine("Enter prof ID: ");
                                int profid = Convert.ToInt16(Console.ReadLine());
                                foreach (Course f in coursesList)
                                {
                                    f.displayCourseInfo();
                                }
                                Console.WriteLine("Enter Course ID: ");
                                int courseId = Convert.ToInt16(Console.ReadLine());
                                foreach (Course x in coursesList)
                                {
                                    if (x.cId == courseId)
                                    {
                                        foreach (Professor p in profList)
                                        {
                                            if (Convert.ToInt16(p.getUid()) == profid)
                                            {
                                                x.professor = p;
                                                x.professor.addCourseToTeach(x);
                                            }
                                        }
                                    }
                                }
                                break;

                            /*
                             * // Test: Currently Assign all courses to 1st prof in the list
                             * foreach (var c in coursesList)
                             * {
                             *  c.professor = (Professor)profList[0];
                             *  c.professor.addCourseToTeach(c);
                             * }
                             * break;
                             */
                            case '7':
                                foreach (var std in courseEnrolls)
                                {
                                    std.displEnrolledStudInfo();
                                }
                                break;
                            } //end switch ch2
                        } while (ch2 != '0');
                    }         // else



                    break;

                case '2':      //  Works for both grad & undergrad using student combined list
                case '3':
                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            //"1- List My courses", "2- Enroll in a course","3- submit course Assesment"
                            ch2 = student.Menu();
                            switch (ch2)
                            {
                            case '1':
                                student.DisplayEnrollments();

                                break;

                            case '2':
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (5): check if stud already enrolled in the course before adding
                                if (selectedCourse != null)
                                {
                                    foreach (Enrollment enrol in courseEnrolls)
                                    {
                                        if (enrol.getCourse() == selectedCourse)
                                        {
                                            if (enrol.getStudent() == student)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    Enrollment tEn = new Enrollment(selectedCourse, student);
                                    courseEnrolls.Add(tEn);
                                    student.addEnrollment(tEn);
                                    selectedCourse.addEnrollment(tEn);
                                }
                                break;


                            case '3':
                                student.DisplayEnrollments();
                                Console.WriteLine("Select Course Id To submit Assessment for: ");

                                cId = int.Parse(Console.ReadLine());

                                //selectedCourse = findCourse(coursesList,  cId);
                                //
                                Enrollment e = student.getEnrolmentByCourseId(cId);
                                if (e != null)
                                {
                                    e.getCourse().displayCourseAssessments();
                                    Console.WriteLine("Select Assessment Id To submit: ");
                                    string assessId = Console.ReadLine().Trim();
                                    e.submitAssesment(assessId, "12/12/2018");
                                }
                                break;

                            case '4':
                                Console.WriteLine("Enter Course ID: ");
                                int courseid = Convert.ToInt16(Console.ReadLine());
                                foreach (Enrollment encorl in courseEnrolls)
                                {
                                    if (encorl.getCourse().cId == courseid)
                                    {
                                        courseEnrolls.Remove(encorl);
                                    }
                                }
                                break;
                                // TODO (6): Drop course, get cId, verify cId in student enrollments, then remove enrol.
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;

                case '4':     //prof

                    Console.WriteLine("\n \t Enter your Id:");
                    tId = Console.ReadLine();
                    Console.Write("\t Enter your Password: "******"\n Error: user Id or password are not correct!");
                    }
                    else
                    {
                        do
                        {
                            // 1- List my courses, 2- Add Assesment to course,3- Update student's Assesment points");
                            // 4- list students in a course
                            ch2 = prof.Menu();
                            switch (ch2)
                            {
                            case '1':
                                prof.displayCourses();
                                break;

                            case '2':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                int cId = int.Parse(Console.ReadLine());

                                Course selectedCourse = findCourse(coursesList, cId);
                                // TODO (7): get assessment type: assignment, exam, proj,...
                                //         : then add assessment info
                                if (selectedCourse != null)
                                {
                                    Console.WriteLine("Enter Assessment info: ");
                                    Console.WriteLine("Enter 1 for Assignment, 2 for Exam: ");
                                    int choice = Convert.ToInt16(Console.ReadKey());
                                    if (choice == 1)
                                    {
                                        Console.WriteLine("Id = ");
                                        string assesId = Console.ReadLine();
                                        Console.WriteLine("Weight = ");
                                        float aPercent = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Descr = ");
                                        string asDescr = Console.ReadLine();
                                        Console.WriteLine("Points = ");
                                        float aPoints = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Due on = ");
                                        string aDueDate = Console.ReadLine();
                                        Console.WriteLine("Late Pen = ");
                                        float latePen = float.Parse(Console.ReadLine());

                                        selectedCourse.AddCourseAssesment(new Assignment(assesId, aPercent, asDescr, aPoints, aDueDate, latePen));
                                    }
                                    if (choice == 2)
                                    {
                                        Console.WriteLine("Id = ");
                                        string assesId = Console.ReadLine();
                                        Console.WriteLine("Weight = ");
                                        float aPercent = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Points = ");
                                        float aPoints = float.Parse(Console.ReadLine());
                                        Console.WriteLine("Due on = ");
                                        string aDueDate = Console.ReadLine();
                                        Console.WriteLine("Att Pen = ");
                                        int att = Convert.ToInt16(Console.ReadLine());

                                        selectedCourse.AddCourseAssesment(new Exam(assesId, aPercent, aPoints, aDueDate, att));
                                    }
                                }


                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW1",0.25f,"written assignment",200,"10/22/18",0.1f));
                                //coursesList[0].AddCourseAssesmsnt(new Exam("MT",0.50f, 200,"10/22/18",2));
                                //coursesList[0].AddCourseAssesmsnt(new Assignment("HW2",0.25f,"written assignment",300,"10/22/18",0.1f));

                                break;

                            case '3':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                    Console.WriteLine("Select student name  ");
                                    //Console.WriteLine(" sName : ");
                                    string sName = Console.ReadLine().Trim();

                                    Student s = selectedCourse.getStudentByName(sName);

                                    Enrollment e = s.getEnrolmentByCourseId(cId);
                                    if (e != null)
                                    {
                                        e.getCourse().displayCourseAssessments();
                                        Console.WriteLine("Select Assessment Id To update: ");
                                        string         assessId       = Console.ReadLine().Trim();
                                        StudAssessment studAssessment = e.getStudAssessmentById(assessId);
                                        Console.WriteLine("Enter assessment Points :");
                                        float newPoints = float.Parse(Console.ReadLine());
                                        studAssessment.updateAssessmentPoints(newPoints);
                                    }
                                }
                                break;

                            case '4':
                                prof.displayCourses();
                                Console.WriteLine("Enter Course Id: ");
                                cId = int.Parse(Console.ReadLine());

                                selectedCourse = findCourse(coursesList, cId);

                                if (selectedCourse != null)
                                {
                                    selectedCourse.displayCourseStudents();
                                }
                                break;
                            } // switch ch2
                        } while (ch2 != '0');
                    }         //else
                    break;
                }// switch ch
            } while (ch != '0');
        }